Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading