Skip to content

Commit

Permalink
eliminate cargo clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
NuLL3rr0r committed Nov 10, 2023
1 parent 13a638a commit 8249f57
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/api/bdaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl TryFrom<u64> for BDAddr {
impl From<BDAddr> for u64 {
fn from(addr: BDAddr) -> Self {
let mut slice = [0; 8];
(&mut slice[2..]).copy_from_slice(&addr.into_inner());
slice[2..].copy_from_slice(&addr.into_inner());
u64::from_be_bytes(slice)
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ use crate::platform::PeripheralId;
serde(crate = "serde_cr")
)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Default)]
pub enum AddressType {
Random,
#[default]
Public,
}

impl Default for AddressType {
fn default() -> Self {
AddressType::Public
}
}


impl AddressType {
#[allow(clippy::should_implement_trait)]
pub fn from_str(v: &str) -> Option<AddressType> {
match v {
"public" => Some(AddressType::Public),
Expand Down
4 changes: 1 addition & 3 deletions src/bluez/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,7 @@ impl From<&ServiceInternal> for Service {
uuid: service.info.uuid,
primary: service.info.primary,
characteristics: service
.characteristics
.iter()
.map(|(_, characteristic)| make_characteristic(characteristic, service.info.uuid))
.characteristics.values().map(|characteristic| make_characteristic(characteristic, service.info.uuid))
.collect(),
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/common/adapter_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ where
PeripheralType: Peripheral + 'static,
{
pub fn emit(&self, event: CentralEvent) {
match event {
CentralEvent::DeviceDisconnected(ref id) => {
self.peripherals.remove(id);
}
_ => {}
if let CentralEvent::DeviceDisconnected(ref id) = event {
self.peripherals.remove(id);
}

if let Err(lost) = self.events_channel.send(event) {
Expand All @@ -59,8 +56,8 @@ where
pub fn event_stream(&self) -> Pin<Box<dyn Stream<Item = CentralEvent> + Send>> {
let receiver = self.events_channel.subscribe();
Box::pin(BroadcastStream::new(receiver).filter_map(|x| async move {
if x.is_ok() {
Some(x.unwrap())
if let Ok(e) = x {
Some(e)
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn notifications_stream_from_broadcast_receiver(
receiver: Receiver<ValueNotification>,
) -> Pin<Box<dyn Stream<Item = ValueNotification> + Send>> {
Box::pin(BroadcastStream::new(receiver).filter_map(|x| async move {
if x.is_ok() {
Some(x.unwrap())
if let Ok(n) = x {
Some(n)
} else {
None
}
Expand Down
6 changes: 3 additions & 3 deletions src/winrtble/ble/characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ use windows::{

pub type NotifiyEventHandler = Box<dyn Fn(Vec<u8>) + Send>;

impl Into<GattWriteOption> for WriteType {
fn into(self) -> GattWriteOption {
match self {
impl From<WriteType> for GattWriteOption {
fn from(val: WriteType) -> Self {
match val {
WriteType::WithoutResponse => GattWriteOption::WriteWithoutResponse,
WriteType::WithResponse => GattWriteOption::WriteWithResponse,
}
Expand Down
15 changes: 7 additions & 8 deletions src/winrtble/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ impl Peripheral {
let (broadcast_sender, _) = broadcast::channel(16);
Peripheral {
shared: Arc::new(Shared {
adapter: adapter,
adapter,
device: tokio::sync::Mutex::new(None),
address: address,
address,
connected: AtomicBool::new(false),
ble_services: DashMap::new(),
notifications_channel: broadcast_sender,
Expand Down Expand Up @@ -124,10 +124,9 @@ impl Peripheral {
.services
.read()
.unwrap()
.iter()
.map(|uuid| *uuid)
.iter().copied()
.collect(),
class: self.shared.class.read().unwrap().clone(),
class: *self.shared.class.read().unwrap(),
}
}

Expand Down Expand Up @@ -251,7 +250,7 @@ impl Peripheral {

self.emit_event(CentralEvent::ServicesAdvertisement {
id: self.shared.address.into(),
services: services_guard.iter().map(|uuid| *uuid).collect(),
services: services_guard.iter().copied().collect(),
});
}
}
Expand Down Expand Up @@ -409,7 +408,7 @@ impl ApiPeripheral for Peripheral {
for service in gatt_services {
let uuid = utils::to_uuid(&service.Uuid().unwrap());
if !self.shared.ble_services.contains_key(&uuid) {
match BLEDevice::get_characteristics(&service).await {
match BLEDevice::get_characteristics(service).await {
Ok(characteristics) => {
let characteristics =
characteristics.into_iter().map(|characteristic| async {
Expand Down Expand Up @@ -499,7 +498,7 @@ impl ApiPeripheral for Peripheral {
let uuid = characteristic.uuid;
ble_characteristic
.subscribe(Box::new(move |value| {
let notification = ValueNotification { uuid: uuid, value };
let notification = ValueNotification { uuid, value };
// Note: we ignore send errors here which may happen while there are no
// receivers...
let _ = notifications_sender.send(notification);
Expand Down
2 changes: 1 addition & 1 deletion src/winrtble/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn to_error(status: GattCommunicationStatus) -> Result<()> {
} else if status == GattCommunicationStatus::ProtocolError {
Err(Error::NotSupported("ProtocolError".to_string()))
} else {
Err(Error::Other(format!("Communication Error:").into()))
Err(Error::Other("Communication Error:".to_string().into()))
}
}

Expand Down

0 comments on commit 8249f57

Please sign in to comment.