rustHow to get pointer to function in Rust
In Rust, you can get a pointer to a function by using the std::mem::transmute
function. This function takes a function pointer and returns a pointer to the function. To use this function, you must first create a function pointer type. For example, if you have a function foo
that takes two i32
parameters and returns an i32
, you can create a function pointer type like this: type FooFnPtr = fn(i32, i32) -> i32;
. Then you can use std::mem::transmute
to get a pointer to the function like this: let foo_ptr: *const FooFnPtr = std::mem::transmute(foo);
. The foo_ptr
variable now holds a pointer to the foo
function.
Helpful links
Related
- How to get pointer of struct in Rust
- Creating pointer from specific address in Rust
- Example of pointer offset in Rust
- Weak pointer example in Rust
- How to get pointer to variable in Rust
- How to get address of pointer in Rust
- How to get pointer of object in Rust
- How to get next pointer in Rust
- How to create pointer in Rust
- How to do pointer write in Rust
More of Rust
- How to get a capture group using Rust regex?
- How to use Unicode in a regex in Rust?
- How to get the last element of a Rust slice?
- How to match the end of a line in a Rust regex?
- How to replace a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use an enum in a Rust HashMap?
- How to match whitespace with a regex in Rust?
- How to split a string with Rust regex?
- How to match a URL with a regex in Rust?
See more codes...