Skip to main content

Tuple

Struct Tuple 

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

An Erlang tuple.

The lean form: a one-word term handle, like every other otter term. Reading its elements is an explicit step — with_elements performs the single enif_get_tuple and yields a TupleView, the collection-like form. Keeping the two separate means a tuple that is only passed through (matched in TypedTerm, re-encoded, compared) never pays for the element fetch.

Implementations§

Source§

impl<'id> Tuple<'id>

Source

pub fn from_raw(raw_term: Term) -> Self

Available on crate feature raw only.
Source

pub fn with_elements(self, env: impl Env<'id>) -> TupleView<'id>

Resolve the tuple’s elements (one enif_get_tuple) into a TupleView.

A Tuple is only ever built from a term already confirmed to be a tuple, so enif_get_tuple cannot fail — a zero return is an internal contract violation, not a user-input case, hence the assert.

Source

pub fn from_terms<I, T>(env: impl Env<'id>, terms: I) -> Tuple<'id>
where I: IntoIterator<Item = T>, T: Term<'id>,

Construct a tuple from any iterable of terms of this brand (enif_make_tuple_from_array).

Source

pub fn is_tuple(env: impl Env<'id>, term: impl Term<'id>) -> bool

Returns true if term is a tuple (enif_is_tuple).

Trait Implementations§

Source§

impl<'id> Clone for Tuple<'id>

Source§

fn clone(&self) -> Tuple<'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 Tuple<'id>

Source§

impl Debug for Tuple<'_>

Source§

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

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

impl<'id> Decoder<'id> for Tuple<'id>

Accepts a tuple of any arity (enif_is_tuple); WrongType otherwise.

Source§

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

Source§

impl<'id> Encoder<'id> for Tuple<'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 Tuple<'_>

Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl Ord for Tuple<'_>

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 Tuple<'_>

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 Tuple<'_>

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 Tuple<'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 Tuple<'id>

§

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

§

impl<'id> Freeze for Tuple<'id>

§

impl<'id> RefUnwindSafe for Tuple<'id>

§

impl<'id> Unpin for Tuple<'id>

§

impl<'id> UnsafeUnpin for Tuple<'id>

§

impl<'id> UnwindSafe for Tuple<'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.