Created
January 22, 2017 12:18
-
-
Save orclev/958eb4fc092f299927851589f44bd219 to your computer and use it in GitHub Desktop.
This file contains 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, 'b:'a> { | |
_context: PhantomData<&'b Context>, | |
usb_context: Box<Context>, | |
device_handle: DeviceHandle<'a>, | |
} | |
impl <'a, 'b> Drop for OpenRadioContext<'a, 'b> { | |
fn drop(&mut self) { | |
self.device_handle.release_interface(0).unwrap(); | |
} | |
} | |
impl <'a, 'b: 'a> OpenRadioContext<'a, 'b> { | |
fn open() -> OpenRadioContext<'a, 'b> { | |
let ctx: Box<Context> = Box::new(Context::new().unwrap()); // Has lifetime b' but Rust doesn't know that | |
let ctx2: &'b Context = &ctx; | |
let mut handle = ctx2.open_device_with_vid_pid(0x1915, 0x7777).and_then(|mut hndl: DeviceHandle<'a>| { | |
hndl.reset(); | |
hndl.set_active_configuration(1).unwrap(); | |
hndl.claim_interface(0).unwrap(); | |
Option::Some(hndl) | |
}).unwrap(); | |
OpenRadioContext { | |
_context: PhantomData, | |
usb_context: ctx, | |
device_handle: handle, | |
} | |
} | |
} | |
---- | |
error: `ctx` does not live long enough | |
--> src/lib.rs:74:34 | |
| | |
74 | let ctx2: &'b Context = &ctx; | |
| ^^^ does not live long enough | |
... | |
86 | } | |
| - borrowed value only lives until here | |
| | |
note: borrowed value must be valid for the lifetime 'b as defined on the body at 72:42... | |
--> src/lib.rs:72:43 | |
| | |
72 | fn open() -> OpenRadioContext<'a, 'b> { | |
| ^ | |
error: aborting due to previous error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment