Last active
January 22, 2017 11:11
-
-
Save orclev/7dbdbd3559b295ce2aa3114f238c736e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pub struct OpenRadioContext<'a> { // public struct | |
usb_context: Context, // private fields, safety depends on these not being accessed directly | |
device_handle: DeviceHandle<'a>, | |
} | |
... snip ... | |
impl <'a> OpenRadioContext<'a> { | |
fn open() -> OpenRadioContext<'a> { | |
let mut ctx: Box<Context> = Box::new(Context::new().unwrap()); // Has lifetime a' but Rust doesn't know that | |
let mut handle = ctx.open_device_with_vid_pid(0x1915, 0x7777).and_then(|mut hndl: DeviceHandle| { | |
hndl.reset(); | |
hndl.set_active_configuration(1).unwrap(); | |
hndl.claim_interface(0).unwrap(); | |
unsafe { | |
Option::Some(transmute::<DeviceHandle, DeviceHandle<'a>>(hndl)) // Ewww | |
} | |
}).unwrap(); | |
OpenRadioContext { // Make sure ctx and handle both have lifetime 'a | |
usb_context: ctx, | |
device_handle: handle, | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment