Compare commits

..

No commits in common. "eb5dc84ca8d29560f4c55c7465e370001f4edf02" and "31d681ba2ad79b63b5f7560aae6b85c8a1ed9d02" have entirely different histories.

3 changed files with 18 additions and 31 deletions

View file

@ -175,18 +175,3 @@ impl Display for PollTimeoutFromIntError {
}
impl Error for PollTimeoutFromIntError {}
#[derive(Debug)]
pub enum MicrosecondsFromDurationError {
NoMicroseconds,
}
impl Display for MicrosecondsFromDurationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoMicroseconds => write!(f, "Minimal precision is microseconds but no microseconds are within the Duration provided."),
}
}
}
impl Error for MicrosecondsFromDurationError {}

View file

@ -349,10 +349,10 @@ pub enum NotifyState<'a> {
/// Tell the service manager to execute the configured watchdog option.
WatchdogTrigger,
/// Reset watchdog timeout value during runtime.
/// Minimal precision is microseconds, not nanoseconds.
/// The value is in microseconds.
WatchdogUsec(types::Microseconds),
/// Tells the service manager to extend the startup, runtime or shutdown service timeout corresponding the current state.
/// Minimal precision is microseconds, not nanoseconds.
/// The value is in microseconds.
ExtendTimeoutUsec(types::Microseconds),
}
@ -373,11 +373,11 @@ impl<'a> Display for NotifyState<'a> {
NotifyState::Stopping => f.write_str("STOPPING=1"),
NotifyState::Watchdog => f.write_str("WATCHDOG=1"),
NotifyState::WatchdogTrigger => f.write_str("WATCHDOG=trigger"),
NotifyState::WatchdogUsec(duration) => {
write!(f, "WATCHDOG_USEC={duration}")
NotifyState::WatchdogUsec(milliseconds) => {
write!(f, "WATCHDOG_USEC={milliseconds}")
}
NotifyState::ExtendTimeoutUsec(duration) => {
write!(f, "EXTEND_TIMEOUT_USEC={duration}")
NotifyState::ExtendTimeoutUsec(milliseconds) => {
write!(f, "EXTEND_TIMEOUT_USEC={milliseconds}")
}
}
}

View file

@ -1,6 +1,6 @@
//! Newtypes used by [`NotifyState`](super::NotifyState)
use core::{fmt::Display, time::Duration};
use core::fmt::Display;
use super::error;
@ -88,22 +88,24 @@ impl Display for StatusLine<'_> {
/// Semantic type representing a number of microseconds.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Microseconds(Duration);
pub struct Microseconds(u64);
impl TryFrom<Duration> for Microseconds {
type Error = error::MicrosecondsFromDurationError;
impl From<u64> for Microseconds {
fn from(value: u64) -> Self {
Self(value)
}
}
fn try_from(value: Duration) -> Result<Self, Self::Error> {
if value.as_micros() == 0 {
return Err(Self::Error::NoMicroseconds);
}
Ok(Self(value))
impl From<Microseconds> for u64 {
fn from(value: Microseconds) -> Self {
value.0
}
}
impl Display for Microseconds {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0.as_micros())
Display::fmt(&self.0, f)
}
}