From 4402ce6478027d48435eb937087690ae41f152c1 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Tue, 20 Jan 2026 15:00:53 +0000 Subject: cargo fmt --- src/command_policy.rs | 4 +--- src/entity_sensor.rs | 4 +--- src/entity_switch.rs | 4 +--- src/mqtt/rx.rs | 18 +++++++++++++----- src/mqtt/tx.rs | 1 - 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/command_policy.rs b/src/command_policy.rs index e5859bb..a1bb3bf 100644 --- a/src/command_policy.rs +++ b/src/command_policy.rs @@ -63,8 +63,7 @@ /// # } /// # async fn turn_on_motor() -> Result<(), ()> { Ok(()) } /// ``` -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[derive(Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum CommandPolicy { /// Automatically publish the entity's state when a command is received. #[default] @@ -73,4 +72,3 @@ pub enum CommandPolicy { /// Do not automatically publish state. The application must manually update the state. Manual, } - diff --git a/src/entity_sensor.rs b/src/entity_sensor.rs index e221141..fd5e7f7 100644 --- a/src/entity_sensor.rs +++ b/src/entity_sensor.rs @@ -18,8 +18,7 @@ impl StateClass { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[derive(Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum SensorClass { #[default] Generic, @@ -77,7 +76,6 @@ pub enum SensorClass { Other(&'static str), } - impl SensorClass { pub fn as_str(&self) -> Option<&'static str> { match self { diff --git a/src/entity_switch.rs b/src/entity_switch.rs index 2b799a1..b685ce5 100644 --- a/src/entity_switch.rs +++ b/src/entity_switch.rs @@ -14,15 +14,13 @@ pub enum SwitchClass { /// Configuration for a switch entity. /// /// See [`CommandPolicy`] for details on how commands are handled. -#[derive(Debug)] -#[derive(Default)] +#[derive(Debug, Default)] pub struct SwitchConfig { pub common: EntityCommonConfig, pub class: SwitchClass, pub command_policy: CommandPolicy, } - impl SwitchConfig { pub(crate) fn populate(&self, config: &mut EntityConfig) { self.common.populate(config); diff --git a/src/mqtt/rx.rs b/src/mqtt/rx.rs index 10b775a..0dfd858 100644 --- a/src/mqtt/rx.rs +++ b/src/mqtt/rx.rs @@ -37,7 +37,9 @@ impl From for Error { fn from(value: varint::Error) -> Self { match value { varint::Error::NeedMoreData => Self::NeedMoreData, - varint::Error::InvalidVarInt => Self::InvalidPacket("invalid variable integer encoding"), + varint::Error::InvalidVarInt => { + Self::InvalidPacket("invalid variable integer encoding") + } } } } @@ -92,8 +94,10 @@ pub fn decode<'a>(buf: &'a [u8]) -> Result<(Packet<'a>, usize), Error> { protocol::PACKET_TYPE_PUBLISH => { // Extract flags from the fixed header let retain = (packet_flags & protocol::PUBLISH_FLAG_RETAIN) != 0; - let qos_value = (packet_flags & protocol::PUBLISH_FLAG_QOS_MASK) >> protocol::PUBLISH_FLAG_QOS_SHIFT; - let qos = Qos::from_u8(qos_value).ok_or(Error::InvalidPacket("PUBLISH has invalid QoS value"))?; + let qos_value = (packet_flags & protocol::PUBLISH_FLAG_QOS_MASK) + >> protocol::PUBLISH_FLAG_QOS_SHIFT; + let qos = Qos::from_u8(qos_value) + .ok_or(Error::InvalidPacket("PUBLISH has invalid QoS value"))?; let dup = (packet_flags & protocol::PUBLISH_FLAG_DUP) != 0; // Track position after fixed header to calculate data length @@ -113,7 +117,9 @@ pub fn decode<'a>(buf: &'a [u8]) -> Result<(Packet<'a>, usize), Error> { let variable_header_len = reader.num_read() - variable_header_start; let data_len = (packet_len as usize) .checked_sub(variable_header_len) - .ok_or(Error::InvalidPacket("PUBLISH remaining length is too short for headers"))?; + .ok_or(Error::InvalidPacket( + "PUBLISH remaining length is too short for headers", + ))?; Packet::Publish { topic, @@ -140,7 +146,9 @@ pub fn decode<'a>(buf: &'a [u8]) -> Result<(Packet<'a>, usize), Error> { } if packet_len < 3 { // Minimum: 2 bytes packet ID + 1 byte return code - return Err(Error::InvalidPacket("SUBACK remaining length must be at least 3")); + return Err(Error::InvalidPacket( + "SUBACK remaining length must be at least 3", + )); } let packet_id = PacketId::from(reader.read_u16()?); let return_code = reader.read_u8()?; diff --git a/src/mqtt/tx.rs b/src/mqtt/tx.rs index 7a4d443..3b2ed66 100644 --- a/src/mqtt/tx.rs +++ b/src/mqtt/tx.rs @@ -209,4 +209,3 @@ pub fn pingreq(buffer: &mut FieldBuffer) { ))); buffer.push(Field::VarInt(0)); } - -- cgit