Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::os::raw::c_void;
- struct Encoder<TCallback>
- where
- TCallback: Fn(&[u8]),
- {
- callback: TCallback,
- }
- type EncoderType = Encoder<Box<Fn(&[u8])>>;
- #[no_mangle]
- unsafe extern "C" fn encoder_create(
- on_data: unsafe extern "C" fn(data: *const u8, length: usize),
- instance: *mut *mut c_void,
- ) -> bool {
- let encoder: EncoderType = Encoder {
- callback: move |data| unsafe { (on_data)(data.as_ptr(), data.len()) },
- };
- *instance = Box::into_raw(Box::new(encoder)) as *mut c_void;
- true
- }
- #[no_mangle]
- pub unsafe extern "C" fn encoder_destroy(instance: *mut c_void) {
- if !instance.is_null() {
- Box::from_raw(instance as *mut EncoderType);
- }
- }
- fn main() {
- println!("Hello, world!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement