Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Option<fn()> in WrapperApi #4

Merged

Commits on Jul 5, 2023

  1. 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) };
    }
    ```
    zitsen committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    743e83e View commit details
    Browse the repository at this point in the history