Content-Length: 40083 | pFad | https://doc.rust-lang.org/reference/items/../names/../items/../types/../types/function-pointer.html

Function pointer types - The Rust Reference

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Function pointer types

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:

#![allow(unused)]
fn main() {
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);
}

Function pointers can be created via a coercion from both function items and non-capturing, non-async closures.

The unsafe qualifier indicates that the type’s value is an unsafe function, and the extern qualifier indicates it is an extern function.

For the function to be variadic, its extern ABI must be one of those listed in items.extern.variadic.conventions.

Attributes on function pointer parameters

Attributes on function pointer parameters follow the same rules and restrictions as regular function parameters.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/reference/items/../names/../items/../types/../types/function-pointer.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy