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>
impl<'id> Integer<'id>
pub fn from_raw(raw_term: Term) -> Self
raw only.Sourcepub fn from_i64(env: impl Env<'id>, val: i64) -> Self
pub fn from_i64(env: impl Env<'id>, val: i64) -> Self
Construct an integer term from an i64 (enif_make_int64).
Sourcepub fn from_u64(env: impl Env<'id>, val: u64) -> Self
pub fn from_u64(env: impl Env<'id>, val: u64) -> Self
Construct an integer term from a u64 (enif_make_uint64).
Sourcepub fn to_i64(self, env: impl Env<'id>) -> Option<i64>
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.
Sourcepub fn to_u64(self, env: impl Env<'id>) -> Option<u64>
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).
Sourcepub fn to_bigint(self, env: impl Env<'id>) -> BigInt
Available on crate feature bigint only.
pub fn to_bigint(self, env: impl Env<'id>) -> BigInt
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.
Sourcepub fn from_bigint(env: impl Env<'id>, val: &BigInt) -> Self
Available on crate feature bigint only.
pub fn from_bigint(env: impl Env<'id>, val: &BigInt) -> Self
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§
impl<'id> Copy for Integer<'id>
Source§impl<'id> Decoder<'id> for Integer<'id>
Accepts an integer term (enif_term_type == Integer); rejects anything else
as WrongType.
impl<'id> Decoder<'id> for Integer<'id>
Accepts an integer term (enif_term_type == Integer); rejects anything else
as WrongType.
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.
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.
impl Eq for Integer<'_>
Source§impl Ord for Integer<'_>
impl Ord for Integer<'_>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Integer<'_>
impl PartialOrd for Integer<'_>
Source§impl<'id> Term<'id> for Integer<'id>
impl<'id> Term<'id> for Integer<'id>
Source§fn copy_to<'dst>(self, env: impl Env<'dst>) -> AnyTerm<'dst>where
Self: Sized,
fn copy_to<'dst>(self, env: impl Env<'dst>) -> AnyTerm<'dst>where
Self: Sized,
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).