pub struct LegacyF64(/* private fields */);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§
Source§impl LegacyF64
impl LegacyF64
Sourcepub fn from_f64(f: f64) -> Option<LegacyF64>
pub fn from_f64(f: f64) -> Option<LegacyF64>
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());Sourcepub unsafe fn from_f64_unchecked(f: f64) -> LegacyF64
pub unsafe fn from_f64_unchecked(f: f64) -> LegacyF64
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) };Sourcepub fn is_valid(f: f64) -> bool
pub fn is_valid(f: f64) -> bool
Checks whether a given f64
may be used as a LegacyF64.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for LegacyF64
impl<'de> Deserialize<'de> for LegacyF64
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for LegacyF64
impl Ord for LegacyF64
Source§impl PartialOrd for LegacyF64
impl PartialOrd for LegacyF64
impl Copy for LegacyF64
impl Eq for LegacyF64
impl StructuralPartialEq for LegacyF64
Auto Trait Implementations§
impl Freeze for LegacyF64
impl RefUnwindSafe for LegacyF64
impl Send for LegacyF64
impl Sync for LegacyF64
impl Unpin for LegacyF64
impl UnwindSafe for LegacyF64
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.