pub struct SerialisedAsPico(/* private fields */);Expand description
A newtype wrapper meant to facilitate CBOR encoding of time::Duration as integers with pico-precision. This may seem odd, but is necessary to mimic the encoding behavior of some Haskell types such as ‘RelativeTime’.
Note that the Haskell RelativeTime truncates to whole seconds, which this helper does not. Haskell should be able to read values encoded by this helper, but will truncate to whole seconds when computing with the values.
TODO: Maybe consider promoting this as RelativeTime, for robustness and to avoid some
confusing naming…
Implementations§
Source§impl SerialisedAsPico
impl SerialisedAsPico
pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>where
D: Deserializer<'de>,
pub fn serialize<S>(
duration: &Duration,
serializer: S,
) -> Result<S::Ok, S::Error>where
S: Serializer,
Trait Implementations§
Source§impl Debug for SerialisedAsPico
impl Debug for SerialisedAsPico
Source§impl<'b, C> Decode<'b, C> for SerialisedAsPico
impl<'b, C> Decode<'b, C> for SerialisedAsPico
Source§impl<C> Encode<C> for SerialisedAsPico
impl<C> Encode<C> for SerialisedAsPico
Source§impl From<Duration> for SerialisedAsPico
impl From<Duration> for SerialisedAsPico
Source§impl From<SerialisedAsPico> for Duration
impl From<SerialisedAsPico> for Duration
Source§fn from(t: SerialisedAsPico) -> Self
fn from(t: SerialisedAsPico) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for SerialisedAsPico
impl RefUnwindSafe for SerialisedAsPico
impl Send for SerialisedAsPico
impl Sync for SerialisedAsPico
impl Unpin for SerialisedAsPico
impl UnsafeUnpin for SerialisedAsPico
impl UnwindSafe for SerialisedAsPico
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more