Trait RealType

Source
pub trait RealType:
    Sized
    + Debug
    + Display {
    const BYTE_WIDTH: usize;
    const INFINITY: Self;
    const NEG_INFINITY: Self;
    const NAN: Self;

    // Required methods
    fn to_ieee754_bytes(&self) -> (impl AsRef<[u8]>, usize);
    fn try_from_ieee754_bytes(bytes: &[u8]) -> Result<Self, TryFromRealError>;
    fn try_from_float(value: impl FloatCore) -> Option<Self>;
    fn try_to_float(&self) -> Option<impl FloatCore>;
    fn is_infinity(&self) -> bool;
    fn is_neg_infinity(&self) -> bool;
    fn is_nan(&self) -> bool;
}
Expand description

Represents a real type in Rust that can be decoded or encoded into any ASN.1 codec.

Required Associated Constants§

Source

const BYTE_WIDTH: usize

The byte level width of the floating point type.

Source

const INFINITY: Self

The infinity (∞) value

Source

const NEG_INFINITY: Self

The negative infinity (-∞) value

Source

const NAN: Self

The Not-a-Number value

Required Methods§

Source

fn to_ieee754_bytes(&self) -> (impl AsRef<[u8]>, usize)

Returns the IEEE 754 encoded bytes of the real type, byte count defined in usize

Source

fn try_from_ieee754_bytes(bytes: &[u8]) -> Result<Self, TryFromRealError>

Attempts to decode the IEEE 754 encoded bytes into Self

Source

fn try_from_float(value: impl FloatCore) -> Option<Self>

Attempts to convert a generic floating point type into Self

Source

fn try_to_float(&self) -> Option<impl FloatCore>

Attempts to convert Self into a generic floating point type

Source

fn is_infinity(&self) -> bool

Returns true if the value is positive infinity

Source

fn is_neg_infinity(&self) -> bool

Returns true if the value is negative infinity

Source

fn is_nan(&self) -> bool

Returns true if the value is NaN

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.

Implementations on Foreign Types§

Source§

impl RealType for f32

Source§

const BYTE_WIDTH: usize = 4usize

Source§

const INFINITY: Self = +Inf_f32

Source§

const NEG_INFINITY: Self = -Inf_f32

Source§

const NAN: Self = NaN_f32

Source§

fn to_ieee754_bytes(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn try_from_ieee754_bytes(bytes: &[u8]) -> Result<Self, TryFromRealError>

Source§

fn try_from_float(value: impl FloatCore) -> Option<Self>

Source§

fn try_to_float(&self) -> Option<impl FloatCore>

Source§

fn is_infinity(&self) -> bool

Source§

fn is_neg_infinity(&self) -> bool

Source§

fn is_nan(&self) -> bool

Source§

impl RealType for f64

Source§

const BYTE_WIDTH: usize = 8usize

Source§

const INFINITY: Self = +Inf_f64

Source§

const NEG_INFINITY: Self = -Inf_f64

Source§

const NAN: Self = NaN_f64

Source§

fn to_ieee754_bytes(&self) -> (impl AsRef<[u8]>, usize)

Source§

fn try_from_ieee754_bytes(bytes: &[u8]) -> Result<Self, TryFromRealError>

Source§

fn try_from_float(value: impl FloatCore) -> Option<Self>

Source§

fn try_to_float(&self) -> Option<impl FloatCore>

Source§

fn is_infinity(&self) -> bool

Source§

fn is_neg_infinity(&self) -> bool

Source§

fn is_nan(&self) -> bool

Implementors§