[fp-rs] Cross-platform Bluetooth now interfaces with impl trait rather than concrete per-platform type.

This commit is contained in:
Lucas Silva Shepard
2023-07-13 16:09:37 -07:00
parent aeed049d58
commit a855dd19e1
3 changed files with 13 additions and 6 deletions
+8 -2
View File
@@ -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<impl Adapter, anyhow::Error> {
BleAdapter::default().await
}
@@ -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<BleDevice, anyhow::Error> {
async fn next_device(&mut self) -> Result<Self::Device, anyhow::Error> {
if let Some(stream) = &mut self.device_stream {
stream
.next()
+2 -2
View File
@@ -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 {