Struct magnus::numeric::NumericValue
source · pub struct NumericValue(/* private fields */);
Expand description
Wrapper type for a Value known to be an instance of Ruby’s Numeric class.
See the ReprValue
trait for additional methods available on this type.
§Examples
use std::num::NonZeroI64;
use magnus::{numeric::NumericValue, prelude::*, Float, Integer, RRational};
let a = Integer::from_i64(1);
let b = RRational::new(1, NonZeroI64::new(2).unwrap());
let c = Float::from_f64(0.3);
let d = Integer::from_i64(4);
let result: NumericValue = a.coerce_bin(b, "+").unwrap();
let result: NumericValue = result.coerce_bin(c, "+").unwrap();
let result: NumericValue = result.coerce_bin(d, "+").unwrap();
assert_eq!(f64::try_convert(result.as_value()).unwrap(), 5.8);
Trait Implementations§
source§impl Clone for NumericValue
impl Clone for NumericValue
source§fn clone(&self) -> NumericValue
fn clone(&self) -> NumericValue
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for NumericValue
impl Debug for NumericValue
source§impl Display for NumericValue
impl Display for NumericValue
source§impl IntoValue for NumericValue
impl IntoValue for NumericValue
source§impl Numeric for NumericValue
impl Numeric for NumericValue
source§fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§impl ReprValue for NumericValue
impl ReprValue for NumericValue
source§fn equal<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
fn equal<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
Checks for equality, delegating to the Ruby method
#==
. Read moresource§fn eql<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
fn eql<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
Checks for equality, delegating to the Ruby method
#eql?
. Read moresource§fn hash(self) -> Result<Integer, Error>
fn hash(self) -> Result<Integer, Error>
Returns an integer non-uniquely identifying
self
. Read moresource§fn to_bool(self) -> bool
fn to_bool(self) -> bool
Convert
self
to a bool
, following Ruby’s rules of false
and nil
as boolean false
and everything else boolean true
. Read moresource§fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
source§fn block_call<M, A, R, T>(
self,
method: M,
args: A,
block: fn(_: &[Value], _: Option<Proc>) -> R
) -> Result<T, Error>
fn block_call<M, A, R, T>( self, method: M, args: A, block: fn(_: &[Value], _: Option<Proc>) -> R ) -> Result<T, Error>
source§fn respond_to<M>(self, method: M, include_private: bool) -> Result<bool, Error>where
M: IntoId,
fn respond_to<M>(self, method: M, include_private: bool) -> Result<bool, Error>where
M: IntoId,
Check if
self
responds to the given Ruby method. Read moresource§fn is_kind_of<T>(self, class: T) -> bool
fn is_kind_of<T>(self, class: T) -> bool
source§fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator ⓘwhere
M: IntoSymbol,
A: ArgList,
fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator ⓘwhere
M: IntoSymbol,
A: ArgList,
source§impl TryConvert for NumericValue
impl TryConvert for NumericValue
impl Copy for NumericValue
Auto Trait Implementations§
impl Freeze for NumericValue
impl RefUnwindSafe for NumericValue
impl Send for NumericValue
impl Sync for NumericValue
impl Unpin for NumericValue
impl UnwindSafe for NumericValue
Blanket Implementations§
source§impl<T> AsRawValue for Twhere
T: ReprValue,
impl<T> AsRawValue for Twhere
T: ReprValue,
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
Mutably borrows from an owned value. Read more