Skip to main content

Integer

Struct Integer 

Source
pub struct Integer<'id> { /* private fields */ }
Expand description

An Erlang integer. Arbitrary precision — small integers are tagged immediates, large integers (bignums) are heap-allocated on the env.

Carries only its env’s brand 'id, not the env itself. An integer can be read back only with an env of the same brand (the 1:1 identity guarantee), so the accessors take the env explicitly rather than the term carrying it.

Implementations§

Source§

impl<'id> Integer<'id>

Source

pub fn from_raw(raw_term: Term) -> Self

Available on crate feature raw only.
Source

pub fn from_i64(env: impl Env<'id>, val: i64) -> Self

Construct an integer term from an i64 (enif_make_int64).

Source

pub fn from_u64(env: impl Env<'id>, val: u64) -> Self

Construct an integer term from a u64 (enif_make_uint64).

Source

pub fn to_i64(self, env: impl Env<'id>) -> Option<i64>

Read back an i64 (enif_get_int64). None if the term does not fit in i64. env must carry the same brand as this term.

Source

pub fn to_u64(self, env: impl Env<'id>) -> Option<u64>

Read back a u64 (enif_get_uint64). None if the term does not fit in u64 (including negatives).

Source

pub fn to_bigint(self, env: impl Env<'id>) -> BigInt

Available on crate feature bigint only.

Read this integer as an arbitrary-precision BigInt, including bignums that exceed i64/u64 — which to_i64 / to_u64 cannot reach, since the NIF API has no accessor beyond enif_get_int64/enif_get_uint64.

Total over every integer term: it serializes the term to the external term format (enif_term_to_binary) and reconstructs the value from the ETF integer encoding. Infallible — the term is already a validated integer, so it always serializes to one of the four ETF integer tags.

Requires the bigint feature.

Source

pub fn from_bigint(env: impl Env<'id>, val: &BigInt) -> Self

Available on crate feature bigint only.

Construct an integer term from an arbitrary-precision BigInt, including values beyond i64/u64.

Values within range go straight through enif_make_int64 / enif_make_uint64; larger magnitudes are emitted as an ETF bignum (SMALL_BIG_EXT/LARGE_BIG_EXT) and parsed back with enif_binary_to_term. Infallible.

Requires the bigint feature.

Trait Implementations§

Source§

impl<'id> Clone for Integer<'id>

Source§

fn clone(&self) -> Integer<'id>

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<'id> Copy for Integer<'id>

Source§

impl Debug for Integer<'_>

Source§

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

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

impl<'id> Decoder<'id> for Integer<'id>

Accepts an integer term (enif_term_type == Integer); rejects anything else as WrongType.

Source§

fn decode(term: AnyTerm<'id>, env: impl Env<'id>) -> Result<Self, CodecError>

Source§

impl<'id> Encoder<'id> for Integer<'id>

Encodes for free by rewrapping the term’s own machine word — an otter term is already an Erlang term. Never fails.

Source§

fn encode(&self, env: impl Env<'id>) -> Result<AnyTerm<'id>, CodecError>

Source§

impl Eq for Integer<'_>

Source§

impl<'id> From<Integer<'id>> for TypedTerm<'id>

Source§

fn from(v: Integer<'id>) -> Self

Converts to this type from the input type.
Source§

impl Ord for Integer<'_>

Source§

fn cmp(&self, other: &Self) -> 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 Integer<'_>

Source§

fn eq(&self, other: &Self) -> 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 Integer<'_>

Source§

fn partial_cmp(&self, other: &Self) -> 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<'id> Term<'id> for Integer<'id>

Source§

fn raw_term(self) -> Term

The raw machine word backing this term.
Source§

fn copy_to<'dst>(self, env: impl Env<'dst>) -> AnyTerm<'dst>
where Self: Sized,

Copy this term into another environment (enif_make_copy), producing a term branded to the destination. The general cross-env copy — distinct from same-brand Encoder (which wraps for free) and from OwnedEnvArena copy_out (the arena exit).

Auto Trait Implementations§

§

impl<'id> !Send for Integer<'id>

§

impl<'id> !Sync for Integer<'id>

§

impl<'id> Freeze for Integer<'id>

§

impl<'id> RefUnwindSafe for Integer<'id>

§

impl<'id> Unpin for Integer<'id>

§

impl<'id> UnsafeUnpin for Integer<'id>

§

impl<'id> UnwindSafe for Integer<'id>

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<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, 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.