hack to make example compile
This commit is contained in:
parent
5276b29670
commit
54ecc210ec
1 changed files with 5 additions and 1 deletions
|
@ -598,17 +598,21 @@ we have function pointers flying across the FFI boundary in both directions.
|
||||||
```rust
|
```rust
|
||||||
use std::os::raw::c_int;
|
use std::os::raw::c_int;
|
||||||
|
|
||||||
|
# #[cfg(hidden)]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
/// Register the callback.
|
/// Register the callback.
|
||||||
fn register(cb: Option<extern "C" fn(Option<extern "C" fn(c_int) -> c_int>, c_int) -> c_int>);
|
fn register(cb: Option<extern "C" fn(Option<extern "C" fn(c_int) -> c_int>, c_int) -> c_int>);
|
||||||
}
|
}
|
||||||
|
# unsafe fn register(_: Option<extern "C" fn(Option<extern "C" fn(c_int) -> c_int>,
|
||||||
|
# c_int) -> c_int>)
|
||||||
|
# {}
|
||||||
|
|
||||||
/// This fairly useless function receives a function pointer and an integer
|
/// This fairly useless function receives a function pointer and an integer
|
||||||
/// from C, and returns the result of calling the function with the integer.
|
/// from C, and returns the result of calling the function with the integer.
|
||||||
/// In case no function is provided, it squares the integer by default.
|
/// In case no function is provided, it squares the integer by default.
|
||||||
extern "C" fn apply(process: Option<extern "C" fn(c_int) -> c_int>, int: c_int) -> c_int {
|
extern "C" fn apply(process: Option<extern "C" fn(c_int) -> c_int>, int: c_int) -> c_int {
|
||||||
match process {
|
match process {
|
||||||
Some(f) => unsafe { f(int) },
|
Some(f) => f(int),
|
||||||
None => int * int
|
None => int * int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue