Skip to main content

NumTo

Trait NumTo 

Source
pub trait NumTo<T> {
    // Required methods
    fn fits(&self) -> bool;
    fn to(&self) -> T;
}
Expand description

Indicates a type to which a MessagePack Rust Num instance can be coverted

Required Methods§

Source

fn fits(&self) -> bool

Will this Num instance fit in the target type? Fits is defined as lossless conversion. E.g. an f64 value of 42.0 will fit in all rust data types, but a u16 value of 256 will not fit in a u8

Source

fn to(&self) -> T

Convert this Num instance into the destination type. If this instance is outside the bounds of the target type, it will be clamped to fit. Check fits() first if this is not desireable

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§