diff --git a/statime-linux/src/main.rs b/statime-linux/src/main.rs index 669fdd02b..f16eff8dc 100644 --- a/statime-linux/src/main.rs +++ b/statime-linux/src/main.rs @@ -36,43 +36,6 @@ use tokio::{ time::Sleep, }; -#[derive(Clone, Copy)] -struct SdoIdParser; - -impl clap::builder::TypedValueParser for SdoIdParser { - type Value = SdoId; - - fn parse_ref( - &self, - cmd: &clap::Command, - arg: Option<&clap::Arg>, - value: &std::ffi::OsStr, - ) -> Result { - use clap::error::{ContextKind, ContextValue, ErrorKind}; - - let inner = clap::value_parser!(u16); - let val = inner.parse_ref(cmd, arg, value)?; - - match SdoId::try_from(val) { - Ok(v) => Ok(v), - Err(()) => { - let mut err = clap::Error::new(ErrorKind::ValueValidation).with_cmd(cmd); - if let Some(arg) = arg { - err.insert( - ContextKind::InvalidArg, - ContextValue::String(arg.to_string()), - ); - } - err.insert( - ContextKind::InvalidValue, - ContextValue::String(val.to_string()), - ); - Err(err) - } - } - } -} - #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] pub struct Args { diff --git a/statime-linux/src/metrics/exporter.rs b/statime-linux/src/metrics/exporter.rs index f0fbf530e..88fe7f552 100644 --- a/statime-linux/src/metrics/exporter.rs +++ b/statime-linux/src/metrics/exporter.rs @@ -7,9 +7,8 @@ use tokio::{ net::{TcpListener, UnixStream}, }; -use crate::{config::Config, observer::ObservableInstanceState}; - use super::format::format_response; +use crate::{config::Config, observer::ObservableInstanceState}; #[derive(Debug, Serialize, Deserialize)] pub struct ObservableState { diff --git a/statime-linux/src/observer.rs b/statime-linux/src/observer.rs index d780ee786..2c9045085 100644 --- a/statime-linux/src/observer.rs +++ b/statime-linux/src/observer.rs @@ -1,8 +1,9 @@ +use std::{fs::Permissions, os::unix::prelude::PermissionsExt, path::Path, time::Instant}; + use statime::{ config::TimePropertiesDS, observability::{current::CurrentDS, default::DefaultDS, parent::ParentDS}, }; -use std::{fs::Permissions, os::unix::prelude::PermissionsExt, path::Path, time::Instant}; use tokio::{io::AsyncWriteExt, net::UnixStream, task::JoinHandle}; use crate::{ @@ -13,13 +14,17 @@ use crate::{ /// Observable version of the InstanceState struct #[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)] pub struct ObservableInstanceState { - /// A concrete implementation of the PTP Default dataset (IEEE1588-2019 section 8.2.1) + /// A concrete implementation of the PTP Default dataset (IEEE1588-2019 + /// section 8.2.1) pub default_ds: DefaultDS, - /// A concrete implementation of the PTP Current dataset (IEEE1588-2019 section 8.2.2) + /// A concrete implementation of the PTP Current dataset (IEEE1588-2019 + /// section 8.2.2) pub current_ds: CurrentDS, - /// A concrete implementation of the PTP Parent dataset (IEEE1588-2019 section 8.2.3) + /// A concrete implementation of the PTP Parent dataset (IEEE1588-2019 + /// section 8.2.3) pub parent_ds: ParentDS, - /// A concrete implementation of the PTP Time Properties dataset (IEEE1588-2019 section 8.2.4) + /// A concrete implementation of the PTP Time Properties dataset + /// (IEEE1588-2019 section 8.2.4) pub time_properties_ds: TimePropertiesDS, } diff --git a/statime/src/datastructures/common/clock_identity.rs b/statime/src/datastructures/common/clock_identity.rs index ad612072c..647e72cbc 100644 --- a/statime/src/datastructures/common/clock_identity.rs +++ b/statime/src/datastructures/common/clock_identity.rs @@ -32,10 +32,6 @@ impl ClockIdentity { } impl WireFormat for ClockIdentity { - fn wire_size(&self) -> usize { - 8 - } - fn serialize(&self, buffer: &mut [u8]) -> Result<(), WireFormatError> { buffer[0..8].copy_from_slice(&self.0); Ok(()) diff --git a/statime/src/datastructures/common/clock_quality.rs b/statime/src/datastructures/common/clock_quality.rs index 68f0f8d2f..e9a9644e8 100644 --- a/statime/src/datastructures/common/clock_quality.rs +++ b/statime/src/datastructures/common/clock_quality.rs @@ -38,10 +38,6 @@ impl Default for ClockQuality { } impl WireFormat for ClockQuality { - fn wire_size(&self) -> usize { - 4 - } - fn serialize(&self, buffer: &mut [u8]) -> Result<(), WireFormatError> { buffer[0] = self.clock_class; buffer[1] = self.clock_accuracy.to_primitive(); diff --git a/statime/src/datastructures/common/port_identity.rs b/statime/src/datastructures/common/port_identity.rs index bb575019b..b83b25535 100644 --- a/statime/src/datastructures/common/port_identity.rs +++ b/statime/src/datastructures/common/port_identity.rs @@ -12,10 +12,6 @@ pub struct PortIdentity { } impl WireFormat for PortIdentity { - fn wire_size(&self) -> usize { - 10 - } - fn serialize(&self, buffer: &mut [u8]) -> Result<(), WireFormatError> { self.clock_identity.serialize(&mut buffer[0..8])?; buffer[8..10].copy_from_slice(&self.port_number.to_be_bytes()); diff --git a/statime/src/datastructures/common/time_interval.rs b/statime/src/datastructures/common/time_interval.rs index fba9641d9..141167d19 100644 --- a/statime/src/datastructures/common/time_interval.rs +++ b/statime/src/datastructures/common/time_interval.rs @@ -26,10 +26,6 @@ impl DerefMut for TimeInterval { } impl WireFormat for TimeInterval { - fn wire_size(&self) -> usize { - 8 - } - fn serialize(&self, buffer: &mut [u8]) -> Result<(), WireFormatError> { buffer[0..8].copy_from_slice(&self.0.to_bits().to_be_bytes()); Ok(()) diff --git a/statime/src/datastructures/common/timestamp.rs b/statime/src/datastructures/common/timestamp.rs index eb7394f6f..d01a7e48c 100644 --- a/statime/src/datastructures/common/timestamp.rs +++ b/statime/src/datastructures/common/timestamp.rs @@ -14,10 +14,6 @@ pub struct WireTimestamp { } impl WireFormat for WireTimestamp { - fn wire_size(&self) -> usize { - 10 - } - fn serialize(&self, buffer: &mut [u8]) -> Result<(), WireFormatError> { buffer[0..6].copy_from_slice(&self.seconds.to_be_bytes()[2..8]); buffer[6..10].copy_from_slice(&self.nanos.to_be_bytes()); diff --git a/statime/src/datastructures/messages/header.rs b/statime/src/datastructures/messages/header.rs index 6c98a661e..a8dd4e178 100644 --- a/statime/src/datastructures/messages/header.rs +++ b/statime/src/datastructures/messages/header.rs @@ -201,8 +201,7 @@ impl<'de> serde::de::Visitor<'de> for SdoIdVisitor { where D: serde::Deserializer<'de>, { - use serde::de::Error; - use serde::Deserialize; + use serde::{de::Error, Deserialize}; let v = u16::deserialize(deserializer)?; SdoId::try_from(v).or(Err(D::Error::custom(std::format!( "SdoId not in range of 0..=0xFFF: {}", diff --git a/statime/src/datastructures/messages/mod.rs b/statime/src/datastructures/messages/mod.rs index 58fd2ccdb..fa5bd2469 100644 --- a/statime/src/datastructures/messages/mod.rs +++ b/statime/src/datastructures/messages/mod.rs @@ -84,8 +84,8 @@ impl TryFrom for MessageType { pub use fuzz::FuzzMessage; #[cfg(feature = "fuzz")] +#[allow(missing_docs)] // These are only used for internal fuzzing mod fuzz { - #![allow(missing_docs)] // These are only used for internal fuzzing use super::*; use crate::datastructures::{common::Tlv, WireFormatError}; diff --git a/statime/src/datastructures/mod.rs b/statime/src/datastructures/mod.rs index 6230a4926..7a3756a6e 100644 --- a/statime/src/datastructures/mod.rs +++ b/statime/src/datastructures/mod.rs @@ -46,9 +46,6 @@ impl From for WireFormatError { } trait WireFormat: Debug + Clone + Eq { - /// The byte size on the wire of this object - fn wire_size(&self) -> usize; - /// Serializes the object into the PTP wire format. /// /// Returns the used buffer size that contains the message or an error. diff --git a/statime/src/float_polyfill.rs b/statime/src/float_polyfill.rs index a7e504fab..e92a82c35 100644 --- a/statime/src/float_polyfill.rs +++ b/statime/src/float_polyfill.rs @@ -1,3 +1,4 @@ +#[allow(unused)] // clippy will inaccurately mark this as unused on platforms with std pub(crate) trait FloatPolyfill { #[cfg(not(feature = "std"))] fn abs(self) -> Self; diff --git a/statime/src/observability/current.rs b/statime/src/observability/current.rs index c49ad861a..f9e5e9b9d 100644 --- a/statime/src/observability/current.rs +++ b/statime/src/observability/current.rs @@ -3,8 +3,8 @@ use crate::datastructures::datasets::InternalCurrentDS; /// A concrete implementation of the PTP Current dataset (IEEE1588-2019 section /// 8.2.2) /// -/// Note that the `meanDelay` field from IEEE1588-2019 section 8.2.2.4 is missing -/// since this field can be constructed from the portDS. +/// Note that the `meanDelay` field from IEEE1588-2019 section 8.2.2.4 is +/// missing since this field can be constructed from the portDS. #[derive(Debug, Default, Copy, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct CurrentDS { diff --git a/statime/src/observability/mod.rs b/statime/src/observability/mod.rs index 6d5dbc902..e216e080a 100644 --- a/statime/src/observability/mod.rs +++ b/statime/src/observability/mod.rs @@ -1,7 +1,10 @@ //! Serializable implementations of datastructures to be used for observability -/// A concrete implementation of the PTP Current dataset (IEEE1588-2019 section 8.2.2) +/// A concrete implementation of the PTP Current dataset (IEEE1588-2019 section +/// 8.2.2) pub mod current; -/// A concrete implementation of the PTP Default dataset (IEEE1588-2019 section 8.2.1) +/// A concrete implementation of the PTP Default dataset (IEEE1588-2019 section +/// 8.2.1) pub mod default; -/// A concrete implementation of the PTP Parent dataset (IEEE1588-2019 section 8.2.3) +/// A concrete implementation of the PTP Parent dataset (IEEE1588-2019 section +/// 8.2.3) pub mod parent; diff --git a/statime/src/port/state.rs b/statime/src/port/state.rs index dcd9e006b..5682a3d28 100644 --- a/statime/src/port/state.rs +++ b/statime/src/port/state.rs @@ -7,6 +7,7 @@ use crate::{ #[derive(Debug, Default)] #[allow(private_interfaces)] +#[allow(clippy::large_enum_variant)] pub(crate) enum PortState { #[default] Faulty,