pub trait Fixable: Sealed + Sized {
// Required method
fn to_fix(self) -> Option<i64>;
// Provided method
fn is_fixable(self) -> bool { ... }
}Expand description
Marker trait for numeric values which can be converted to a “fixnum”, or Integer, representation.
A numeric value is fixable if its integral portion can fit within 63 bits of
an i64.
See RUBY_FIXNUM_MIN and RUBY_FIXNUM_MAX for more details on the range
of values yielded by implementers of this trait.
This trait is sealed and cannot be implemented outside of this crate.
Required Methods§
Provided Methods§
Sourcefn is_fixable(self) -> bool
fn is_fixable(self) -> bool
Test whether a fixable numeric value is in range.
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 Fixable for f32
impl Fixable for f32
Source§fn to_fix(self) -> Option<i64>
fn to_fix(self) -> Option<i64>
Convert an f32 to a fixnum if it is less than or equal to
RUBY_FIXNUM_MAX and greater than or equal to RUBY_FIXNUM_MIN in
magnitude.
This method returns None if the receiver is greater than
RUBY_FIXNUM_MAX or less than RUBY_FIXNUM_MIN.
This function discards the fractional part of the float, i.e. truncates.
NaN and infinities return None.
§Implementation Notes
Conversion is implemented using checked operations and will never panic.
This conversion is implemented using Duration::try_from_secs_f32 and
extracting the the integral portion of the float via Duration::as_secs.
Source§impl Fixable for f64
impl Fixable for f64
Source§fn to_fix(self) -> Option<i64>
fn to_fix(self) -> Option<i64>
Convert an f64 to a fixnum if it is less than or equal to
RUBY_FIXNUM_MAX and greater than or equal to RUBY_FIXNUM_MIN in
magnitude.
This method returns None if the receiver is greater than
RUBY_FIXNUM_MAX or less than RUBY_FIXNUM_MIN.
This function discards the fractional part of the float, i.e. truncates.
NaN and infinities return None.
§Implementation Notes
Conversion is implemented using checked operations and will never panic.
This conversion is implemented using Duration::try_from_secs_f64 and
extracting the the integral portion of the float via Duration::as_secs.
Source§impl Fixable for i64
impl Fixable for i64
Source§fn to_fix(self) -> Option<i64>
fn to_fix(self) -> Option<i64>
Convert an i64 to a fixnum if it is less than or equal to
RUBY_FIXNUM_MAX and greater than or equal to RUBY_FIXNUM_MIN in
magnitude.
This method returns None if the receiver is greater than
RUBY_FIXNUM_MAX or less than RUBY_FIXNUM_MIN.
Source§fn is_fixable(self) -> bool
fn is_fixable(self) -> bool
Test whether an i64 value is in range of fixnum.
This method returns false if the receiver is greater than
RUBY_FIXNUM_MAX or less than RUBY_FIXNUM_MAX.
Source§impl Fixable for i128
impl Fixable for i128
Source§fn to_fix(self) -> Option<i64>
fn to_fix(self) -> Option<i64>
Convert an i128 to a fixnum if it is less than or equal to
RUBY_FIXNUM_MAX and greater than or equal to RUBY_FIXNUM_MIN in
magnitude.
This method returns None if the receiver is greater than
RUBY_FIXNUM_MAX or less than RUBY_FIXNUM_MIN.
Source§fn is_fixable(self) -> bool
fn is_fixable(self) -> bool
Test whether an i128 value is in range of fixnum.
This method returns false if the receiver is greater than
RUBY_FIXNUM_MAX or less than RUBY_FIXNUM_MAX.
Source§impl Fixable for u64
impl Fixable for u64
Source§fn to_fix(self) -> Option<i64>
fn to_fix(self) -> Option<i64>
Convert a u64 to a fixnum if it is less than or equal to
RUBY_FIXNUM_MAX in magnitude.
This method returns None if the receiver is greater than
RUBY_FIXNUM_MAX.
Source§fn is_fixable(self) -> bool
fn is_fixable(self) -> bool
Test whether a u64 value is in range of fixnum.
This method returns false if the receiver is greater than
RUBY_FIXNUM_MAX.
Source§impl Fixable for u128
impl Fixable for u128
Source§fn to_fix(self) -> Option<i64>
fn to_fix(self) -> Option<i64>
Convert a u128 to a fixnum if it is less than or equal to
RUBY_FIXNUM_MAX in magnitude.
This method returns None if the receiver is greater than
RUBY_FIXNUM_MAX.
Source§fn is_fixable(self) -> bool
fn is_fixable(self) -> bool
Test whether a u128 value is in range of fixnum.
This method returns false if the receiver is greater than
RUBY_FIXNUM_MAX.