Skip to content

Commit 826fc68

Browse files
authored
Merge pull request #1718 from ehuss/function-pointer-example
Move the function pointer example
2 parents a79047d + 6322604 commit 826fc68

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/types/function-pointer.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,22 @@ r[type.fn-pointer.intro]
2929
Function pointer types, written using the `fn` keyword, refer to a function
3030
whose identity is not necessarily known at compile-time.
3131

32+
An example where `Binop` is defined as a function pointer type:
33+
34+
```rust
35+
fn add(x: i32, y: i32) -> i32 {
36+
x + y
37+
}
38+
39+
let mut x = add(5,7);
40+
41+
type Binop = fn(i32, i32) -> i32;
42+
let bo: Binop = add;
43+
x = bo(5,7);
44+
```
45+
3246
r[type.fn-pointer.coercion]
33-
They can be created via a coercion from both [function items] and non-capturing, non-async [closures].
47+
Function pointers can be created via a coercion from both [function items] and non-capturing, non-async [closures].
3448

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

50-
An example where `Binop` is defined as a function pointer type:
51-
52-
```rust
53-
fn add(x: i32, y: i32) -> i32 {
54-
x + y
55-
}
56-
57-
let mut x = add(5,7);
58-
59-
type Binop = fn(i32, i32) -> i32;
60-
let bo: Binop = add;
61-
x = bo(5,7);
62-
```
63-
6464
r[type.fn-pointer.attributes]
6565
## Attributes on function pointer parameters
6666

0 commit comments

Comments
 (0)