Skip to main content

Int

Struct Int 

Source
pub struct Int { /* private fields */ }
Expand description

A signed integer of arbitrary size.

use ion_rs::{Element, Int};

let element = Element::read_one("-42")?;

// Access the element's integer value...
let int: &Int = element.expect_int()?;
// ...and convert it to an i64. `as_i64()` will return `None` if
// the Int is too large to fit in an i64.
assert_eq!(int.as_i64(), Some(-42i64));

// The `expect_i64()` is similar to `as_i64()`, but returns an
// `IonError` instead of `None` if the conversion cannot be completed.
assert_eq!(element.expect_i64()?, -42i64);

Implementations§

Source§

impl Int

Source

pub const ZERO: Int

Source

pub fn unsigned_abs(&self) -> UInt

Returns a UInt representing the unsigned magnitude of this Int.

Source

pub fn is_negative(&self) -> bool

Returns true if this value is less than zero. If this value is greater than or equal to zero, returns false.

Source

pub fn expect_i64(&self) -> IonResult<i64>

If this value is small enough to fit in an i64, returns Ok(i64). Otherwise, returns a DecodingError.

Source

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

Source

pub fn expect_u32(&self) -> IonResult<u32>

Source

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

Source

pub fn expect_u64(&self) -> IonResult<u64>

Source

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

Source

pub fn expect_usize(&self) -> IonResult<usize>

Source

pub fn expect_i128(&self) -> IonResult<i128>

If this value is small enough to fit in an i128, returns Ok(i128). Otherwise, returns a DecodingError.

Source

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

If this value is small enough to fit in an i64, returns Some(i64). Otherwise, returns None.

Source

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

If this value is small enough to fit in an i128, returns Some(i128). Otherwise, returns None.

Source

pub fn from_le_signed_bytes(bytes: &[u8]) -> Int

Source

pub fn to_le_signed_bytes(&self) -> Vec<u8>

Source

pub fn is_zero(&self) -> bool

Returns true if this value is zero.

Source

pub fn neg(self) -> Self

Returns the negation of this value.

Trait Implementations§

Source§

impl Clone for Int

Source§

fn clone(&self) -> Int

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Int

Source§

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

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

impl Display for Int

Source§

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

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

impl Eq for Int

Source§

impl From<&Int> for Int

Source§

fn from(value: &Int) -> Self

Converts to this type from the input type.
Source§

impl From<&UInt> for Int

Source§

fn from(value: &UInt) -> Self

Converts to this type from the input type.
Source§

impl From<Int> for Coefficient

Source§

fn from(value: Int) -> Coefficient

Converts to this type from the input type.
Source§

impl From<Int> for Decimal

Source§

fn from(value: Int) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Int
where T: Into<IntData>,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl Hash for Int

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 Ord for Int

Source§

fn cmp(&self, other: &Int) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Int

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Int

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for Int

Source§

impl TryFrom<&Coefficient> for Int

Source§

type Error = IonError

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

fn try_from(value: &Coefficient) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Int> for UInt

Source§

type Error = IonError

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

fn try_from(value: &Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Coefficient> for Int

Source§

type Error = IonError

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

fn try_from(value: Coefficient) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for UInt

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for i8

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for i16

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for i32

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for i64

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for i128

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for isize

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for u8

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for u16

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for u32

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for u64

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for u128

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Int> for usize

Source§

type Error = IonError

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

fn try_from(value: Int) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Int

§

impl RefUnwindSafe for Int

§

impl Send for Int

§

impl Sync for Int

§

impl Unpin for Int

§

impl UnsafeUnpin for Int

§

impl UnwindSafe for Int

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> 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<V> IntoAnnotatedElement for V
where V: Into<Value>,

Source§

fn with_annotations<I: IntoAnnotations>(self, annotations: I) -> Element

Converts the value into an Element with the specified annotations.
Source§

impl<T> ToCompactString for T
where T: Display,

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.