From a89e506d4ae7d48580b205924b7687585f834d95 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sun, 20 Jul 2025 10:54:46 +0200 Subject: [PATCH] fix: switch to &str in ble --- src/ble.rs | 10 +++++----- src/main.rs | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ble.rs b/src/ble.rs index 655949e..dc78952 100644 --- a/src/ble.rs +++ b/src/ble.rs @@ -73,7 +73,7 @@ impl Device { /// Return all supported devices that are found in two seconds. /// /// Returns all badges that are in BLE range and are in Bluetooth transfer mode. - pub async fn enumerate(device_name: &String) -> Result> { + pub async fn enumerate(device_name: &str) -> Result> { Self::enumerate_duration(Duration::from_secs(2), device_name).await } @@ -84,7 +84,7 @@ impl Device { /// This function panics if it is unable to access the Bluetooth adapter. pub async fn enumerate_duration( scan_duration: Duration, - device_name: &String, + device_name: &str, ) -> Result> { // Run device scan let manager = Manager::new().await.context("create BLE manager")?; @@ -117,7 +117,7 @@ impl Device { Ok(led_badges) } - async fn from_peripheral(peripheral: Peripheral, device_name: &String) -> Option { + async fn from_peripheral(peripheral: Peripheral, device_name: &str) -> Option { // The existance of the service with the correct UUID // exists is already checked by the scan filter. // But we also need to check the device name to make sure @@ -137,8 +137,8 @@ impl Device { /// /// This function returns an error if no device could be found /// or if multiple devices would match. - pub async fn single(device_name: Option) -> Result { - let device_name = &device_name.unwrap_or(BADGE_BLE_DEVICE_NAME.to_string()); + pub async fn single(device_name: Option<&str>) -> Result { + let device_name = device_name.unwrap_or(BADGE_BLE_DEVICE_NAME); let mut devices = Self::enumerate(device_name) .await .context("enumerating badges")? diff --git a/src/main.rs b/src/main.rs index 6cddd98..8cdc0c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -244,6 +244,11 @@ fn write_payload( TransportProtocol::Ble => tokio::runtime::Builder::new_current_thread() .enable_all() .build()? - .block_on(async { BleDevice::single(device_name).await?.write(payload).await }), + .block_on(async { + BleDevice::single(device_name.as_deref()) + .await? + .write(payload) + .await + }), } }