Skip to content

Commit

Permalink
Various clippy and formatting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 authored and rnijveld committed Apr 5, 2024
1 parent 3845563 commit cc8216a
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 75 deletions.
37 changes: 0 additions & 37 deletions statime-linux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Value, clap::Error> {
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 {
Expand Down
3 changes: 1 addition & 2 deletions statime-linux/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions statime-linux/src/observer.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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,
}

Expand Down
4 changes: 0 additions & 4 deletions statime/src/datastructures/common/clock_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 0 additions & 4 deletions statime/src/datastructures/common/clock_quality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions statime/src/datastructures/common/port_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 0 additions & 4 deletions statime/src/datastructures/common/time_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 0 additions & 4 deletions statime/src/datastructures/common/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions statime/src/datastructures/messages/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down
2 changes: 1 addition & 1 deletion statime/src/datastructures/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl TryFrom<u8> 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};

Expand Down
3 changes: 0 additions & 3 deletions statime/src/datastructures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ impl From<EnumConversionError> 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.
Expand Down
1 change: 1 addition & 0 deletions statime/src/float_polyfill.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions statime/src/observability/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions statime/src/observability/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions statime/src/port/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{

#[derive(Debug, Default)]
#[allow(private_interfaces)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum PortState {
#[default]
Faulty,
Expand Down

0 comments on commit cc8216a

Please sign in to comment.