From a855dd19e1dc30dbf9d42deccd55e675be59b082 Mon Sep 17 00:00:00 2001 From: Lucas Silva Shepard Date: Thu, 13 Jul 2023 15:34:11 -0700 Subject: [PATCH] [fp-rs] Cross-platform Bluetooth now interfaces with impl trait rather than concrete per-platform type. --- fastpair/rust/src/bluetooth/mod.rs | 10 ++++++++-- fastpair/rust/src/bluetooth/windows_ble/adapter.rs | 5 +++-- fastpair/rust/src/main.rs | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fastpair/rust/src/bluetooth/mod.rs b/fastpair/rust/src/bluetooth/mod.rs index ae8a64e6..2faa2576 100644 --- a/fastpair/rust/src/bluetooth/mod.rs +++ b/fastpair/rust/src/bluetooth/mod.rs @@ -18,12 +18,18 @@ pub mod common; +pub use common::{Adapter, Device}; + cfg_if::cfg_if! { if #[cfg(windows)] { mod windows_ble; - pub use windows_ble::*; + use windows_ble::BleAdapter; } else { mod unsupported; - pub use unsupported::*; + use unsupported::BleAdapter; } } + +pub async fn default_adapter() -> Result { + BleAdapter::default().await +} diff --git a/fastpair/rust/src/bluetooth/windows_ble/adapter.rs b/fastpair/rust/src/bluetooth/windows_ble/adapter.rs index 82929e52..6d7af121 100644 --- a/fastpair/rust/src/bluetooth/windows_ble/adapter.rs +++ b/fastpair/rust/src/bluetooth/windows_ble/adapter.rs @@ -54,7 +54,8 @@ use windows::{ Foundation::TypedEventHandler, }; -use crate::bluetooth::{common::Adapter, BleDevice}; +use super::BleDevice; +use crate::bluetooth::common::Adapter; /// Concrete type implementing `Adapter`, used for Windows BLE. pub struct BleAdapter { @@ -202,7 +203,7 @@ impl Adapter for BleAdapter { } } - async fn next_device(&mut self) -> Result { + async fn next_device(&mut self) -> Result { if let Some(stream) = &mut self.device_stream { stream .next() diff --git a/fastpair/rust/src/main.rs b/fastpair/rust/src/main.rs index d50996d4..5905e135 100644 --- a/fastpair/rust/src/main.rs +++ b/fastpair/rust/src/main.rs @@ -16,11 +16,11 @@ use futures::executor; mod bluetooth; -use bluetooth::common::{Adapter, Device}; +use bluetooth::{Adapter, Device}; fn main() -> Result<(), anyhow::Error> { let run = async { - let mut adapter = bluetooth::BleAdapter::default().await?; + let mut adapter = bluetooth::default_adapter().await?; adapter.start_scan_devices()?; while let Ok(device) = adapter.next_device().await {