Skip to main content

SerialisedAsPico

Struct SerialisedAsPico 

Source
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

Source

pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where D: Deserializer<'de>,

Source

pub fn serialize<S>( duration: &Duration, serializer: S, ) -> Result<S::Ok, S::Error>
where S: Serializer,

Trait Implementations§

Source§

impl Debug for SerialisedAsPico

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'b, C> Decode<'b, C> for SerialisedAsPico

Source§

fn decode(d: &mut Decoder<'b>, _ctx: &mut C) -> Result<Self, Error>

Decode a value using the given Decoder. Read more
Source§

fn nil() -> Option<Self>

If possible, return a nil value of Self. Read more
Source§

impl<C> Encode<C> for SerialisedAsPico

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, ctx: &mut C, ) -> Result<(), Error<W::Error>>

Encode a value of this type using the given Encoder. Read more
Source§

fn is_nil(&self) -> bool

Is this value of Self a nil value? Read more
Source§

impl From<Duration> for SerialisedAsPico

Source§

fn from(d: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<SerialisedAsPico> for Duration

Source§

fn from(t: SerialisedAsPico) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'a, T> Fragment<'a> for T
where T: Encode<()> + Decode<'a, ()>,

Source§

fn encode_fragment(&self) -> Result<Vec<u8>, Box<dyn Error>>

Source§

fn decode_fragment(bytes: &'a [u8]) -> Result<T, Box<dyn Error>>

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Fragment for T
where T: for<'b> Decode<'b, ()> + Encode<()>,