forked from ahmed-masud/rust-dlopen
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support Option<fn()> in WrapperApi
```rust use dlopen2::wrapper::{Container, WrapperApi}; use std::os::raw::c_int; struct Api<'a> { c_fun: unsafe extern "C" fn(), // A function may not exist in the library. c_option_fun: Option<unsafe extern "C" fn() -> c_int>, } fn main(){ let mut cont: Container<Api> = unsafe { Container::load("libexample.so") }.expect("Could not open library or load symbols"); unsafe{ cont.c_fun() }; if cont.has_c_option_fun() { // do something } // option function returns Option<fn_return_type>, it's Option<c_int> here. unsafe{ cont.c_option_fun().map(|i| i == 0) }; } ```
- Loading branch information
Showing
3 changed files
with
110 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters