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

derive support for C-like fn pointers and core::ptr::NonNull #752

Closed
Crzyrndm opened this issue May 5, 2023 · 0 comments · Fixed by #753
Closed

derive support for C-like fn pointers and core::ptr::NonNull #752

Crzyrndm opened this issue May 5, 2023 · 0 comments · Fixed by #753

Comments

@Crzyrndm
Copy link
Contributor

Crzyrndm commented May 5, 2023

When generating a Rust binding to a C struct containing function pointers, bindgen outputs type definitions that look roughly like the following

pub type c_library_callback_t = ::core::option::Option<
    unsafe extern "C" fn(
        param1: Param1Type,
    ),
>;

#[repr(C)]
#[derive(Debug)]
pub struct c_library_api {
    pub callback: c_library_callback_t 
}

with the bindgen ParseCallbacks::add_derives interface, I can add defmt::Format to all of the bindings without issue, however I currently need to manually make exceptions for any type that includes C function pointers and any struct including those structs.

The std Debug impl is just printing the function pointer. Don't see any reason why defmt shouldn't do exactly the same
image

On a strongly related topic, core::ptr::NonNull is a fairly common need when wrapping a generated C-API (at least, from what I've written wrappers for) and doesn't currently have defmt support

@Crzyrndm Crzyrndm changed the title derive support for C-like fn pointers derive support for C-like fn pointers and core::ptr::NonNull May 5, 2023
@bors bors bot closed this as completed in f6e86bc May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant