Skip to main content

Integer

Struct Integer 

Source
pub struct Integer(pub BigInt);

Tuple Fields§

§0: BigInt

Implementations§

Source§

impl Integer

Source

pub fn new<T: Into<BigInt>>(value: T) -> Self

Source

pub fn from_string(s: &str) -> Result<Self, NumberParseError>

Parse an integer from a string in base 10. Returns an error if the string is not a valid integer.

Source

pub fn from_string_radix(s: &str, radix: u32) -> Result<Self, NumberParseError>

Parse an integer from a string in the given radix (base). Returns an error if the string is not a valid integer in the given radix.

Source

pub fn is_zero(&self) -> bool

Returns true if the integer is zero.

Source

pub fn is_negative(&self) -> bool

Returns true if the integer is negative. Note that zero is neither positive nor negative.

Source

pub fn is_positive(&self) -> bool

Returns true if the integer is positive. Note that zero is neither positive nor negative.

Source

pub fn as_i8(&self) -> Option<i8>

Converts the integer to an i8 if it fits, otherwise returns None.

Source

pub fn as_u8(&self) -> Option<u8>

Converts the integer to a u8 if it fits, otherwise returns None.

Source

pub fn as_i16(&self) -> Option<i16>

Converts the integer to an i16 if it fits, otherwise returns None.

Source

pub fn as_u16(&self) -> Option<u16>

Converts the integer to a u16 if it fits, otherwise returns None.

Source

pub fn as_i32(&self) -> Option<i32>

Converts the integer to an i32 if it fits, otherwise returns None.

Source

pub fn as_u32(&self) -> Option<u32>

Converts the integer to a u32 if it fits, otherwise returns None.

Source

pub fn as_i64(&self) -> Option<i64>

Converts the integer to an i64 if it fits, otherwise returns None.

Source

pub fn as_usize(&self) -> Option<usize>

Converts the integer to a usize if it fits, otherwise returns None.

Source

pub fn as_u64(&self) -> Option<u64>

Converts the integer to a u64 if it fits, otherwise returns None.

Source

pub fn as_i128(&self) -> Option<i128>

Converts the integer to an i128 if it fits, otherwise returns None.

Source

pub fn as_u128(&self) -> Option<u128>

Converts the integer to a u128 if it fits, otherwise returns None.

Source

pub fn as_f32(&self) -> f32

Source

pub fn as_f64(&self) -> f64

Source

pub fn as_wrapped_i8(&self) -> i8

Converts the integer to an i8, wrapping on overflow.

Source

pub fn as_wrapped_u8(&self) -> u8

Converts the integer to a u8, wrapping on overflow.

Source

pub fn as_wrapped_i16(&self) -> i16

Source

pub fn as_wrapped_u16(&self) -> u16

Source

pub fn as_wrapped_i32(&self) -> i32

Source

pub fn as_wrapped_u32(&self) -> u32

Source

pub fn as_wrapped_i64(&self) -> i64

Source

pub fn as_wrapped_u64(&self) -> u64

Source

pub fn as_wrapped_i128(&self) -> i128

Source

pub fn as_wrapped_u128(&self) -> u128

Source

pub fn to_smallest_fitting(&self) -> TypedInteger

Converts the integer to the smallest fitting TypedInteger variant. If it doesn’t fit in any smaller type, returns TypedInteger::Big.

Trait Implementations§

Source§

impl Add for &Integer

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Integer

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl BinRead for Integer

Source§

type Args<'a> = ()

The type used for the args parameter of read_args() and read_options(). Read more
Source§

fn read_options<R: Read + Seek>( reader: &mut R, _endian: Endian, _: Self::Args<'_>, ) -> BinResult<Self>

Read Self from the reader using the given Endian and arguments. Read more
Source§

fn read_be<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments and assuming big-endian byte order. Read more
Source§

fn read_le<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments and assuming little-endian byte order. Read more
Source§

fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read T from the reader assuming native-endian byte order. Read more
Source§

fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read Self from the reader, assuming big-endian byte order, using the given arguments. Read more
Source§

fn read_le_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read Self from the reader, assuming little-endian byte order, using the given arguments. Read more
Source§

fn read_ne_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read T from the reader, assuming native-endian byte order, using the given arguments. Read more
Source§

impl BinWrite for Integer

Source§

type Args<'a> = ()

The type used for the args parameter of write_args() and write_options(). Read more
Source§

fn write_options<W: Write + Seek>( &self, writer: &mut W, _endian: Endian, _: Self::Args<'_>, ) -> BinResult<()>

Write Self to the writer using the given Endian and arguments. Read more
Source§

fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming big-endian byte order. Read more
Source§

fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming little-endian byte order. Read more
Source§

fn write_ne<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming native-endian byte order. Read more
Source§

fn write_be_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming big-endian byte order, using the given arguments. Read more
Source§

fn write_le_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming little-endian byte order, using the given arguments. Read more
Source§

fn write_ne_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming native-endian byte order, using the given arguments. Read more
Source§

impl Clone for Integer

Source§

fn clone(&self) -> Integer

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 Integer

Source§

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

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

impl<'de> Deserialize<'de> for Integer

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Integer

Source§

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

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

impl From<BigInt> for Integer

Source§

fn from(value: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<Integer> for CoreValue

Source§

fn from(value: Integer) -> Self

Converts to this type from the input type.
Source§

impl From<Integer> for StructuralTypeDefinition

Source§

fn from(value: Integer) -> Self

Converts to this type from the input type.
Source§

impl From<TypedInteger> for Integer

Source§

fn from(value: TypedInteger) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Integer

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Integer

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Integer

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Integer

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Integer

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Integer

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Integer

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Integer

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Integer

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Integer

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl Hash for Integer

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Neg for Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Integer

Source§

fn eq(&self, other: &Integer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Integer

Source§

fn partial_cmp(&self, other: &Integer) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Integer

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralEq for Integer

Source§

fn structural_eq(&self, other: &Self) -> bool

Check if two values are equal, ignoring the type.
Source§

impl Sub for &Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Eq for Integer

Source§

impl StructuralPartialEq for Integer

Auto Trait Implementations§

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> 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> CustomError for T
where T: Display + Debug + Send + Sync + 'static,

Source§

fn as_any(&self) -> &(dyn Any + Send + Sync + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + Send + Sync + 'static)

Source§

fn as_box_any(self: Box<T>) -> Box<dyn Any + Send + Sync>

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,