[−][src]Struct rosy::Integer
An instance of Ruby's Integer
class.
Logical Binary Operations
The logical operations AND, OR, and XOR are all supported:
use rosy::Integer; let a_val = 0b1101; let b_val = 0b0111; let a_int = Integer::from(a_val); let b_int = Integer::from(b_val); assert_eq!(a_int & b_int, a_val & b_val); assert_eq!(a_int | b_int, a_val | b_val); assert_eq!(a_int ^ b_int, a_val ^ b_val);
Methods
impl Integer
[src]
pub fn unpack<W: Word>(buf: &[W]) -> Self
[src]
Unpacks the contents of buf
into a new instance, making the result
negative if is_negative
.
pub fn unpack_using<W: Word>(buf: &[W], options: PackOptions) -> Self
[src]
Unpacks the contents of buf
into a new instance using options
,
making the result negative if is_negative
.
pub fn is_positive(self) -> bool
[src]
Returns whether self >= 0
.
Examples
use rosy::Integer; let big = Integer::from(u128::max_value()); let fix = Integer::from(isize::max_value() / 2); assert!(big.is_positive()); assert!(fix.is_positive());
pub fn is_negative(self) -> bool
[src]
Returns whether self < 0
.
Examples
use rosy::Integer; let big = Integer::from(i128::min_value()); let fix = Integer::from(isize::min_value() / 2); assert!(big.is_negative()); assert!(fix.is_negative());
pub fn is_bignum(self) -> bool
[src]
Returns whether self
is a variable-sized integer.
pub fn is_fixnum(self) -> bool
[src]
Returns whether self
is a fixed-sized integer.
pub fn fixnum_value(self) -> Option<i64>
[src]
Returns the value of the fixed-width integer stored in self
.
pub fn to_value<W: Word>(self) -> Option<W>
[src]
Converts self
to W
if it can represent be represented as W
.
pub fn to_truncated<W: Word>(self) -> W
[src]
Converts self
to its inner value as W
, truncating on too large or
small of a value.
Examples
This has the same exact behavior as an
as
cast
between integer primitives in Rust:
let val = u16::max_value(); let int = rosy::Integer::from(val); assert_eq!(int.to_truncated::<u16>(), val); assert_eq!(int.to_truncated::<u8>(), 255); assert_eq!(int.to_truncated::<i8>(), -1);
pub fn pack<W: Word>(self, buf: &mut [W]) -> PackSign
[src]
Packs the contents of self
into buf
with the platform's native byte
order.
Examples
use std::slice; use rosy::Integer; let value = u128::max_value() / 0xF00F; let integer = Integer::from(value); let mut buf = [0u128; 2]; integer.pack(&mut buf); assert_eq!(buf[0], value);
pub fn pack_using<W: Word>(
self,
options: PackOptions,
buf: &mut [W]
) -> PackSign
[src]
self,
options: PackOptions,
buf: &mut [W]
) -> PackSign
Packs the contents of self
into buf
using options
.
Examples
use std::slice; use rosy::integer::{Integer, PackOptions}; let value = u128::max_value() / 0xF00F; let integer = Integer::from(value); let mut be_buf = [0u128; 1]; integer.pack_using(PackOptions::big_endian(), &mut be_buf); assert_eq!(be_buf[0], value.to_be()); let mut le_buf = [0u128; 1]; integer.pack_using(PackOptions::little_endian(), &mut le_buf); assert_eq!(le_buf[0], value.to_le());
pub fn can_represent<W: Word>(self) -> bool
[src]
Returns whether self
can represent the word type W
.
Trait Implementations
impl Object for Integer
[src]
fn unique_id() -> Option<u128>
[src]
fn cast<A: Object>(object: A) -> Option<Self>
[src]
fn ty(self) -> Ty
[src]
fn is_ty(self, ty: Ty) -> bool
[src]
unsafe fn from_raw(raw: usize) -> Self
[src]
Creates a new object from raw
without checking. Read more
unsafe fn cast_unchecked(obj: impl Object) -> Self
[src]
Casts obj
to Self
without checking its type.
fn into_any_object(self) -> AnyObject
[src]
Returns self
as an AnyObject
.
fn as_any_object(&self) -> &AnyObject
[src]
Returns a reference to self
as an AnyObject
.
fn as_any_slice(&self) -> &[AnyObject]
[src]
Returns self
as a reference to a single-element slice.
fn raw(self) -> usize
[src]
Returns the raw object pointer.
unsafe fn as_unchecked<O: Object>(&self) -> &O
[src]
Casts self
to O
without checking whether it is one.
unsafe fn into_unchecked<O: Object>(self) -> O
[src]
Converts self
to O
without checking whether it is one.
fn id(self) -> u64
[src]
Returns the object's identifier.
fn class(self) -> Class
[src]
Returns the Class
for self
.
fn singleton_class(self) -> Class
[src]
Returns the singleton Class
of self
, creating one if it doesn't exist already. Read more
fn mark(self)
[src]
Marks self
for Ruby to avoid garbage collecting it.
unsafe fn force_recycle(self)
[src]
Forces the garbage collector to free the contents of self
. Read more
fn def_singleton_method<N, F>(self, name: N, f: F) -> Result where
N: Into<SymbolId>,
F: MethodFn,
[src]
N: Into<SymbolId>,
F: MethodFn,
Defines a method for name
on the singleton class of self
that calls f
when invoked. Read more
unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F) where
N: Into<SymbolId>,
F: MethodFn,
[src]
N: Into<SymbolId>,
F: MethodFn,
Defines a method for name
on the singleton class of self
that calls f
when invoked. Read more
fn call(self, method: impl Into<SymbolId>) -> Result<AnyObject>
[src]
Calls method
on self
and returns the result.
unsafe fn call_unchecked(self, method: impl Into<SymbolId>) -> AnyObject
[src]
Calls method
on self
and returns the result. Read more
fn call_with(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
Calls method
on self
with args
and returns the result.
unsafe fn call_with_unchecked(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
Calls method
on self
with args
and returns the result. Read more
fn call_public(self, method: impl Into<SymbolId>) -> Result<AnyObject>
[src]
Calls the public method
on self
and returns the result.
unsafe fn call_public_unchecked(self, method: impl Into<SymbolId>) -> AnyObject
[src]
Calls the public method
on self
and returns the result. Read more
fn call_public_with(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
Calls the public method
on self
with args
and returns the result.
unsafe fn call_public_with_unchecked(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
Calls the public method
on self
with args
and returns the result. Read more
fn inspect(self) -> String
[src]
Returns a printable string representation of self
. Read more
fn to_s(self) -> String
[src]
Returns the result of calling the to_s
method on self
.
fn is_frozen(self) -> bool
[src]
Returns whether modifications can be made to self
.
fn freeze(self)
[src]
Freezes self
, preventing any further mutations.
fn is_eql<O: Object>(self, other: &O) -> bool
[src]
Returns whether self
is equal to other
in terms of the eql?
method. Read more
impl AsRef<AnyObject> for Integer
[src]
impl Clone for Integer
[src]
fn clone(&self) -> Integer
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Ord for Integer
[src]
fn cmp(&self, other: &Integer) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl From<Integer> for AnyObject
[src]
impl From<usize> for Integer
[src]
impl From<isize> for Integer
[src]
impl From<u128> for Integer
[src]
impl From<i128> for Integer
[src]
impl From<u64> for Integer
[src]
impl From<i64> for Integer
[src]
impl From<u32> for Integer
[src]
impl From<i32> for Integer
[src]
impl From<u16> for Integer
[src]
impl From<i16> for Integer
[src]
impl From<u8> for Integer
[src]
impl From<i8> for Integer
[src]
impl Eq for Integer
[src]
impl Copy for Integer
[src]
impl PartialOrd<Integer> for Integer
[src]
fn partial_cmp(&self, other: &Integer) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<usize> for Integer
[src]
fn partial_cmp(&self, other: &usize) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<u128> for Integer
[src]
fn partial_cmp(&self, other: &u128) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<u64> for Integer
[src]
fn partial_cmp(&self, other: &u64) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<u32> for Integer
[src]
fn partial_cmp(&self, other: &u32) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<u16> for Integer
[src]
fn partial_cmp(&self, other: &u16) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<u8> for Integer
[src]
fn partial_cmp(&self, other: &u8) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<isize> for Integer
[src]
fn partial_cmp(&self, other: &isize) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<i128> for Integer
[src]
fn partial_cmp(&self, other: &i128) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<i64> for Integer
[src]
fn partial_cmp(&self, other: &i64) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<i32> for Integer
[src]
fn partial_cmp(&self, other: &i32) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<i16> for Integer
[src]
fn partial_cmp(&self, other: &i16) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<i8> for Integer
[src]
fn partial_cmp(&self, other: &i8) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<O: Object> PartialEq<O> for Integer
[src]
fn eq(&self, other: &O) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<usize> for Integer
[src]
fn eq(&self, int: &usize) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u128> for Integer
[src]
fn eq(&self, int: &u128) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u64> for Integer
[src]
fn eq(&self, int: &u64) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u32> for Integer
[src]
fn eq(&self, int: &u32) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u16> for Integer
[src]
fn eq(&self, int: &u16) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u8> for Integer
[src]
fn eq(&self, int: &u8) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<isize> for Integer
[src]
fn eq(&self, int: &isize) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<i128> for Integer
[src]
fn eq(&self, int: &i128) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<i64> for Integer
[src]
fn eq(&self, int: &i64) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<i32> for Integer
[src]
fn eq(&self, int: &i32) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<i16> for Integer
[src]
fn eq(&self, int: &i16) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<i8> for Integer
[src]
fn eq(&self, int: &i8) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Debug for Integer
[src]
impl Display for Integer
[src]
impl BitAnd<Integer> for Integer
[src]
type Output = Self
The resulting type after applying the &
operator.
fn bitand(self, rhs: Self) -> Self
[src]
impl BitOr<Integer> for Integer
[src]
type Output = Self
The resulting type after applying the |
operator.
fn bitor(self, rhs: Self) -> Self
[src]
impl BitXor<Integer> for Integer
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,