Thanks to visit codestin.com
Credit goes to docs.rs

Fixnum

Struct Fixnum 

Source
pub struct Fixnum(/* private fields */);
Expand description

A Value known to be a fixnum, Ruby’s internal representation of small integers.

See also Integer.

See the ReprValue trait for additional methods available on this type. See Ruby for methods to create a Fixnum.

Implementations§

Source§

impl Fixnum

Source

pub fn from_value(val: Value) -> Option<Self>

Return Some(Fixnum) if val is a Fixnum, None otherwise.

§Examples
use magnus::{eval, Fixnum};

assert!(Fixnum::from_value(eval("0").unwrap()).is_some());
// too big
assert!(Fixnum::from_value(eval("9223372036854775807").unwrap()).is_none());
// not an int
assert!(Fixnum::from_value(eval("1.23").unwrap()).is_none());
Source

pub fn from_i64(n: i64) -> Result<Self, RBignum>

Available on crate feature old-api only.

Create a new Fixnum from an i64.

Returns Ok(Fixnum) if n is in range for Fixnum, otherwise returns Err(RBignum).

§Panics

Panics if called from a non-Ruby thread. See Ruby::fixnum_from_i64 for the non-panicking version.

§Examples
use magnus::Fixnum;

assert!(Fixnum::from_i64(0).is_ok());
// too big
assert!(Fixnum::from_i64(4611686018427387904).is_err());
assert!(Fixnum::from_i64(-4611686018427387905).is_err());
Source

pub fn from_u64(n: u64) -> Result<Self, RBignum>

Available on crate feature old-api only.

Create a new Fixnum from a u64.

Returns Ok(Fixnum) if n is in range for Fixnum, otherwise returns Err(RBignum).

§Panics

Panics if called from a non-Ruby thread. See Ruby::fixnum_from_u64 for the non-panicking version.

§Examples
use magnus::Fixnum;

assert!(Fixnum::from_u64(0).is_ok());
// too big
assert!(Fixnum::from_u64(4611686018427387904).is_err());
Source

pub fn to_i8(self) -> Result<i8, Error>

Convert self to an i8. Returns Err if self is out of range for i8.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(ruby.eval::<Fixnum>("127")?.to_i8()?, 127);
    assert!(ruby.eval::<Fixnum>("128")?.to_i8().is_err());
    assert_eq!(ruby.eval::<Fixnum>("-128")?.to_i8()?, -128);
    assert!(ruby.eval::<Fixnum>("-129")?.to_i8().is_err());

    Ok(())
}
Source

pub fn to_i16(self) -> Result<i16, Error>

Convert self to an i16. Returns Err if self is out of range for i16.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(ruby.eval::<Fixnum>("32767")?.to_i16()?, 32767);
    assert!(ruby.eval::<Fixnum>("32768")?.to_i16().is_err());
    assert_eq!(ruby.eval::<Fixnum>("-32768")?.to_i16()?, -32768);
    assert!(ruby.eval::<Fixnum>("-32769")?.to_i16().is_err());

    Ok(())
}
Source

pub fn to_i32(self) -> Result<i32, Error>

Convert self to an i32. Returns Err if self is out of range for i32.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(ruby.eval::<Fixnum>("2147483647")?.to_i32()?, 2147483647);
    assert!(ruby.eval::<Fixnum>("2147483648")?.to_i32().is_err());
    assert_eq!(ruby.eval::<Fixnum>("-2147483648")?.to_i32()?, -2147483648);
    assert!(ruby.eval::<Fixnum>("-2147483649")?.to_i32().is_err());

    Ok(())
}
Source

pub fn to_i64(self) -> i64

Convert self to an i64. This is infallible as i64 can represent a larger range than Fixnum.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(
        ruby.eval::<Fixnum>("4611686018427387903")?.to_i64(),
        4611686018427387903
    );
    assert_eq!(
        ruby.eval::<Fixnum>("-4611686018427387904")?.to_i64(),
        -4611686018427387904
    );

    Ok(())
}
Source

pub fn to_i128(self) -> i128

Convert self to an i128. This is infallible as i128 can represent a larger range than Fixnum.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(
        ruby.eval::<Fixnum>("4611686018427387903")?.to_i128(),
        4611686018427387903
    );
    assert_eq!(
        ruby.eval::<Fixnum>("-4611686018427387904")?.to_i128(),
        -4611686018427387904
    );

    Ok(())
}
Source

pub fn to_isize(self) -> isize

Convert self to an isize. Returns Err if self is out of range for isize.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(
        ruby.eval::<Fixnum>("4611686018427387903")?.to_isize(),
        4611686018427387903
    );
    assert_eq!(
        ruby.eval::<Fixnum>("-4611686018427387904")?.to_isize(),
        -4611686018427387904
    );

    Ok(())
}
Source

pub fn to_u8(self) -> Result<u8, Error>

Convert self to a u8. Returns Err if self is negative or out of range for u8.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(ruby.eval::<Fixnum>("255")?.to_u8()?, 255);
    assert!(ruby.eval::<Fixnum>("256")?.to_u8().is_err());
    assert!(ruby.eval::<Fixnum>("-1")?.to_u8().is_err());

    Ok(())
}
Source

pub fn to_u16(self) -> Result<u16, Error>

Convert self to a u16. Returns Err if self is negative or out of range for u16.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(ruby.eval::<Fixnum>("65535")?.to_u16()?, 65535);
    assert!(ruby.eval::<Fixnum>("65536")?.to_u16().is_err());
    assert!(ruby.eval::<Fixnum>("-1")?.to_u16().is_err());

    Ok(())
}
Source

pub fn to_u32(self) -> Result<u32, Error>

Convert self to a u32. Returns Err if self is negative or out of range for u32.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(ruby.eval::<Fixnum>("4294967295")?.to_u32()?, 4294967295);
    assert!(ruby.eval::<Fixnum>("4294967296")?.to_u32().is_err());
    assert!(ruby.eval::<Fixnum>("-1")?.to_u32().is_err());

    Ok(())
}
Source

pub fn to_u64(self) -> Result<u64, Error>

Convert self to a u64. Returns Err if self is negative.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(
        ruby.eval::<Fixnum>("4611686018427387903")?.to_u64()?,
        4611686018427387903
    );
    assert!(ruby.eval::<Fixnum>("-1")?.to_u64().is_err());

    Ok(())
}
Source

pub fn to_u128(self) -> Result<u128, Error>

Convert self to a u128. Returns Err if self is negative.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(
        ruby.eval::<Fixnum>("4611686018427387903")?.to_u128()?,
        4611686018427387903
    );
    assert!(ruby.eval::<Fixnum>("-1")?.to_u128().is_err());

    Ok(())
}
Source

pub fn to_usize(self) -> Result<usize, Error>

Convert self to a usize. Returns Err if self is negative or out of range for usize.

§Examples
use magnus::{Error, Fixnum, Ruby};

fn example(ruby: &Ruby) -> Result<(), Error> {
    assert_eq!(
        ruby.eval::<Fixnum>("4611686018427387903")?.to_usize()?,
        4611686018427387903
    );
    assert!(ruby.eval::<Fixnum>("-1")?.to_usize().is_err());

    Ok(())
}

Trait Implementations§

Source§

impl Clone for Fixnum

Source§

fn clone(&self) -> Fixnum

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fixnum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Fixnum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoValue for Fixnum

Source§

fn into_value_with(self, _: &Ruby) -> Value

Convert self into Value.
Source§

fn into_value(self) -> Value

Available on crate feature old-api only.
Convert self into Value. Read more
Source§

unsafe fn into_value_unchecked(self) -> Value

Convert self into Value. Read more
Source§

impl Numeric for Fixnum

Source§

fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
Source§

fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
Source§

fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
Source§

fn coerce_bit<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
Source§

impl ReprValue for Fixnum

Source§

fn as_value(self) -> Value

Return self as a Value.
Source§

fn is_nil(self) -> bool

Returns whether self is Ruby’s nil value. Read more
Source§

fn equal<T>(self, other: T) -> Result<bool, Error>
where T: ReprValue,

Checks for equality, delegating to the Ruby method #==. Read more
Source§

fn eql<T>(self, other: T) -> Result<bool, Error>
where T: ReprValue,

Checks for equality, delegating to the Ruby method #eql?. Read more
Source§

fn hash(self) -> Result<Integer, Error>

Returns an integer non-uniquely identifying self. Read more
Source§

fn class(self) -> RClass

Returns the class that self is an instance of. Read more
Source§

fn is_frozen(self) -> bool

Returns whether self is ‘frozen’. Read more
Source§

fn check_frozen(self) -> Result<(), Error>

Returns an error if self is ‘frozen’. Read more
Source§

fn freeze(self)

Mark self as frozen. Read more
Source§

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 more
Source§

fn funcall<M, A, T>(self, method: M, args: A) -> Result<T, Error>
where M: IntoId, A: ArgList, T: TryConvert,

Call the method named method on self with args. Read more
Source§

fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
where M: IntoId, A: ArgList, T: TryConvert,

Call the public method named method on self with args. Read more
Source§

fn check_funcall<M, A, T>(self, method: M, args: A) -> Option<Result<T, Error>>
where M: IntoId, A: ArgList, T: TryConvert,

If self responds to the method named method, call it with args. Read more
Source§

fn funcall_with_block<M, A, T>( self, method: M, args: A, block: Proc, ) -> Result<T, Error>
where M: IntoId, A: ArgList, T: TryConvert,

Call the method named method on self with args and block. Read more
Source§

fn block_call<M, A, R, T>( self, method: M, args: A, block: fn(&Ruby, &[Value], Option<Proc>) -> R, ) -> Result<T, Error>
where M: IntoId, A: ArgList, R: BlockReturn, T: TryConvert,

Call the method named method on self with args and block. Read more
Source§

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 more
Source§

fn to_r_string(self) -> Result<RString, Error>

Convert self to a Ruby String. Read more
Source§

unsafe fn to_s(&self) -> Result<Cow<'_, str>, Error>

Convert self to a Rust string. Read more
Source§

fn inspect(self) -> String

Convert self to its Ruby debug representation. Read more
Source§

unsafe fn classname(&self) -> Cow<'_, str>

Return the name of self’s class. Read more
Source§

fn is_kind_of<T>(self, class: T) -> bool
where T: ReprValue + Module,

Returns whether or not self is an instance of class. Read more
Source§

fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator
where M: IntoSymbol, A: ArgList,

Generate an Enumerator from method on self, passing args to method. Read more
Source§

impl TryConvert for Fixnum

Source§

fn try_convert(val: Value) -> Result<Self, Error>

Convert val into Self.
Source§

impl Copy for Fixnum

Source§

impl TryConvertOwned for Fixnum

Auto Trait Implementations§

§

impl Freeze for Fixnum

§

impl RefUnwindSafe for Fixnum

§

impl !Send for Fixnum

§

impl !Sync for Fixnum

§

impl Unpin for Fixnum

§

impl UnwindSafe for Fixnum

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsRawValue for T
where T: ReprValue,

Source§

fn as_raw(self) -> u64

Available on crate feature rb-sys only.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Inspect for T
where T: Debug,

Source§

fn inspect(&self) -> String

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> BlockReturn for T
where T: BlockReturn,

Source§

impl<T> Locate for T
where T: ReprValue,

Source§

impl<T> Mark for T
where T: ReprValue,

Source§

impl<T> ReturnValue for T
where T: ReturnValue,