pub trait AsTimes: Sized {
// Required methods
fn as_times(&self) -> (u64, u64);
fn parse_to_duration(s: &str) -> Result<Self, Error>;
fn from_times(&self, s: u64, ns: u64) -> Self;
}Expand description
AsTimes is the trait that allows FancyDuration to represent durations. Implementing these methods will allow any compatible type to work with FancyDuration.
Required Methods§
Sourcefn as_times(&self) -> (u64, u64)
fn as_times(&self) -> (u64, u64)
To implement a fancier duration, just have your duration return the seconds and nanoseconds (in a tuple) as a part of the following method call, as well as a method to handle parsing. The nanoseconds value should just represent the subsecond count, not the seconds.
Sourcefn parse_to_duration(s: &str) -> Result<Self, Error>
fn parse_to_duration(s: &str) -> Result<Self, Error>
This function implements parsing to return the inner duration. FancyDuration::parse_to_ns is the standard parser and provides you with data to construct most duration types.
Sourcefn from_times(&self, s: u64, ns: u64) -> Self
fn from_times(&self, s: u64, ns: u64) -> Self
Yield one of this implementing duration from a pair of (seconds, nanoseconds).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.