Struct ssb_legacy_msg_data::LegacyF64[][src]

pub struct LegacyF64(_);
Expand description

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.

Implementations

Safe conversion of an arbitrary f64 into a LegacyF64.

use ssb_legacy_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());

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_legacy_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) };

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.