Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. pub struct OpenRadioContext<'a, 'b:'a> {
  2. _context: PhantomData<&'b Context>,
  3. usb_context: Box<Context>,
  4. device_handle: DeviceHandle<'a>,
  5. }
  6.  
  7. impl <'a, 'b> Drop for OpenRadioContext<'a, 'b> {
  8. fn drop(&mut self) {
  9. self.device_handle.release_interface(0).unwrap();
  10. }
  11. }
  12.  
  13. impl <'a, 'b: 'a> OpenRadioContext<'a, 'b> {
  14. fn open() -> OpenRadioContext<'a, 'b> {
  15. let ctx: Box<Context> = Box::new(Context::new().unwrap()); // Has lifetime b' but Rust doesn't know that
  16. let ctx2: &'b Context = &ctx;
  17. let mut handle = ctx2.open_device_with_vid_pid(0x1915, 0x7777).and_then(|mut hndl: DeviceHandle<'a>| {
  18. hndl.reset();
  19. hndl.set_active_configuration(1).unwrap();
  20. hndl.claim_interface(0).unwrap();
  21. Option::Some(hndl)
  22. }).unwrap();
  23. OpenRadioContext {
  24. _context: PhantomData,
  25. usb_context: ctx,
  26. device_handle: handle,
  27. }
  28. }
  29. }
  30.  
  31. ----
  32.  
  33. error: `ctx` does not live long enough
  34. --> src/lib.rs:74:34
  35. |
  36. 74 | let ctx2: &'b Context = &ctx;
  37. | ^^^ does not live long enough
  38. ...
  39. 86 | }
  40. | - borrowed value only lives until here
  41. |
  42. note: borrowed value must be valid for the lifetime 'b as defined on the body at 72:42...
  43. --> src/lib.rs:72:43
  44. |
  45. 72 | fn open() -> OpenRadioContext<'a, 'b> {
  46. | ^
  47.  
  48. error: aborting due to previous error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement