Skip to content

Commit

Permalink
Merge pull request #1718 from ehuss/function-pointer-example
Browse files Browse the repository at this point in the history
Move the function pointer example
  • Loading branch information
traviscross authored Jan 21, 2025
2 parents a79047d + 6322604 commit 826fc68
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/types/function-pointer.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,22 @@ r[type.fn-pointer.intro]
Function pointer types, written using the `fn` keyword, refer to a function
whose identity is not necessarily known at compile-time.

An example where `Binop` is defined as a function pointer type:

```rust
fn add(x: i32, y: i32) -> i32 {
x + y
}

let mut x = add(5,7);

type Binop = fn(i32, i32) -> i32;
let bo: Binop = add;
x = bo(5,7);
```

r[type.fn-pointer.coercion]
They can be created via a coercion from both [function items] and non-capturing, non-async [closures].
Function pointers can be created via a coercion from both [function items] and non-capturing, non-async [closures].

r[type.fn-pointer.qualifiers]
The `unsafe` qualifier indicates that the type's value is an [unsafe
Expand All @@ -47,20 +61,6 @@ these calling conventions:
* `win64`
* `efiapi`

An example where `Binop` is defined as a function pointer type:

```rust
fn add(x: i32, y: i32) -> i32 {
x + y
}

let mut x = add(5,7);

type Binop = fn(i32, i32) -> i32;
let bo: Binop = add;
x = bo(5,7);
```

r[type.fn-pointer.attributes]
## Attributes on function pointer parameters

Expand Down

0 comments on commit 826fc68

Please sign in to comment.