From 47934e3c7ca64bfb82fbcede47491084a9e9f266 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sun, 25 Apr 2021 09:28:58 +0300 Subject: Restore dynamic trait polymorphism with handles in functions --- src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 9fe48b3..65d545c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,17 +16,17 @@ const KNOWN_DEVICES: [(u16, u16, &str); 2] = [ ]; pub struct RtlSdr { - // handle: RtlSdrDeviceHandle, + handle: RtlSdrDeviceHandle, } impl RtlSdr { pub fn new() -> RtlSdr { pretty_env_logger::init(); - let handle = Self::open_device(); - RtlSdr {} + let handle = Self::open_device().unwrap(); + RtlSdr { handle } } - pub fn open_device() { + pub fn open_device() -> Option { for dev in rusb::devices().unwrap().iter() { let desc = dev.device_descriptor().unwrap(); let vid = desc.vendor_id(); @@ -50,9 +50,12 @@ impl RtlSdr { handle.set_i2c_repeater(true); handle.init_tuner(); + + return Some(handle); } } } + None } // pub fn set_sample_rate(&self, samp_rate: u32) { -- cgit v1.3.1