From 8af8dd4a0c47aca78a6eac8b4afe53ec9df2c6be Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Thu, 26 Jul 2018 18:13:45 +0300 Subject: Extract libusb context to a longer living lifetime This is due to a limitation where we can't hold a struct that has both the context and a device handle (that internally references back to it). The libusb context has to outlive the device handle. Github issue: https://github.com/dcuddeback/libusb-rs/issues/3 Example solution via IRC: https://play.rust-lang.org/?gist=c68bda27266249c781e6335c4127f301&version=stable&mode=debug&edition=2015 --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index e1dfc5d..1bdade5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use lib::RtlSdr; fn main() { println!("Running"); - let mut rtlsdr = RtlSdr::new(); + let ctx = libusb::Context::new().unwrap(); + let mut rtlsdr = RtlSdr::new(&ctx); rtlsdr.init(); } -- cgit v1.3.1