[][src]Struct ssb_json_msg_data::LegacyF64

pub struct LegacyF64(_);

A wrapper around f64 to indicate that the float is compatible with the ssb legacy message data model, i.e. it is neither an infinity, nor -0.0, nor a NaN.

Because a LegacyF64 is never NaN, it can implement Eq and Ord, which regular f64 can not.

To obtain the inner value, use the From<LegacyF64> for f64 impl.

Methods

impl LegacyF64[src]

pub fn from_f64(f: f64) -> Option<LegacyF64>[src]

Safe conversion of an arbitrary f64 into a LegacyF64.

use ssb_json_msg_data::LegacyF64;

assert!(LegacyF64::from_f64(0.0).is_some());
assert!(LegacyF64::from_f64(-1.1).is_some());
assert!(LegacyF64::from_f64(-0.0).is_none());
assert!(LegacyF64::from_f64(std::f64::INFINITY).is_none());
assert!(LegacyF64::from_f64(std::f64::NEG_INFINITY).is_none());
assert!(LegacyF64::from_f64(std::f64::NAN).is_none());

pub unsafe fn from_f64_unchecked(f: f64) -> LegacyF64[src]

Wraps the given f64 as a LegacyF64 without checking if it is valid.

When the debug_assertions feature is enabled (when compiling without optimizations), this function panics when given an invalid f64.

Safety

You must not pass infinity, negative infinity, negative zero or a NaN to this function. Any method on the resulting LegacyF64 could panic or exhibit undefined behavior.

use ssb_json_msg_data::LegacyF64;

let fine = unsafe { LegacyF64::from_f64_unchecked(1.1) };

// Never do this:
// let everything_is_terrible = unsafe { LegacyF64::from_f64_unchecked(-0.0) };

pub fn is_valid(f: f64) -> bool[src]

Checks whether a given f64 may be used as a LegacyF64.

Trait Implementations

impl Clone for LegacyF64[src]

impl Copy for LegacyF64[src]

impl Debug for LegacyF64[src]

impl Default for LegacyF64[src]

impl<'de> Deserialize<'de> for LegacyF64[src]

impl Display for LegacyF64[src]

impl Eq for LegacyF64[src]

impl From<LegacyF64> for f64[src]

impl Ord for LegacyF64[src]

impl PartialEq<LegacyF64> for LegacyF64[src]

impl PartialOrd<LegacyF64> for LegacyF64[src]

impl Serialize for LegacyF64[src]

impl StructuralPartialEq for LegacyF64[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.