Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement