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

Made high::Type::make public so CType can be implemented #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marcustut
Copy link

This is to provide a solution for #48

In projects that uses bindgen, it would generate structs such as

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct trade_event {
    pub size: u64,
    pub price: u64,
    pub side: side,
}

and if one has a function pointer such as

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct event_handler {
    pub handle_trade_event: ::std::option::Option<unsafe extern "C" fn(event: trade_event)>,
}

Then, at the moment it won't work because trade_event doesn't implement CType. Although CType is public but high::Type::make is not hence it is not possible to implement CType outside of the crate.

After this change, users are able to implement CType on their own. For example,

unsafe impl CType for trade_event {
    fn reify() -> libffi::high::Type<Self> {
        libffi::high::Type::make(libffi::middle::Type::structure([
            libffi::middle::Type::u64(),    // size
            libffi::middle::Type::u64(),    // price
            libffi::middle::Type::c_uint(), // side
        ]))
    }

    type RetType = trade_event;
}

Now that trade_event implements CType, it is possible to construct the function pointer as shown above for event_handler.

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 this pull request may close these issues.

1 participant