mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
[fp-rs] Cross-platform Bluetooth now interfaces with impl trait rather than concrete per-platform type.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user