pub trait Decoder<'id>: Sized {
// Required method
fn decode(
term: AnyTerm<'id>,
env: impl Env<'id>,
) -> Result<Self, CodecError>;
}Expand description
Extract a value from an Erlang term of brand 'id.
Implemented by otter term types. Takes the raw AnyTerm plus an env (the
term carries only its brand, not its env), so each impl pays exactly the type
check it needs. Returns Err(CodecError) if the term is not the expected
type or the value does not fit.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>, J: Decoder<'id>, K: Decoder<'id>, L: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I, J, K, L)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>, J: Decoder<'id>, K: Decoder<'id>, L: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I, J, K, L)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>, J: Decoder<'id>, K: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I, J, K)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>, J: Decoder<'id>, K: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I, J, K)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>, J: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I, J)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>, J: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I, J)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>, I: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H, I)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>, H: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G, H)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>, G: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F, G)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>, F: Decoder<'id>> Decoder<'id> for (A, B, C, D, E, F)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>> Decoder<'id> for (A, B, C, D, E)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>, E: Decoder<'id>> Decoder<'id> for (A, B, C, D, E)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>> Decoder<'id> for (A, B, C, D)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>, D: Decoder<'id>> Decoder<'id> for (A, B, C, D)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>> Decoder<'id> for (A, B, C)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>, C: Decoder<'id>> Decoder<'id> for (A, B, C)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>, B: Decoder<'id>> Decoder<'id> for (A, B)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>, B: Decoder<'id>> Decoder<'id> for (A, B)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, A: Decoder<'id>> Decoder<'id> for (A,)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
impl<'id, A: Decoder<'id>> Decoder<'id> for (A,)
Requires an Erlang tuple of exactly N elements
(WrongArity otherwise), then decodes each
element in turn; an element’s own error propagates.
Source§impl<'id, K, V, S> Decoder<'id> for HashMap<K, V, S>
Requires an Erlang map, decoding each pair into the HashMap. Generic over
the hasher S. A key/value’s own error propagates.
impl<'id, K, V, S> Decoder<'id> for HashMap<K, V, S>
Requires an Erlang map, decoding each pair into the HashMap. Generic over
the hasher S. A key/value’s own error propagates.
Source§impl<'id, T: Decoder<'id>> Decoder<'id> for Vec<T>
Requires a proper list, decoding each element into the Vec. An improper
tail is WrongType; an element’s own error
propagates.
impl<'id, T: Decoder<'id>> Decoder<'id> for Vec<T>
Requires a proper list, decoding each element into the Vec. An improper
tail is WrongType; an element’s own error
propagates.
Source§impl<'id> Decoder<'id> for bool
Accepts exactly the atoms true/false; every other term — including any
other atom — is WrongType.
impl<'id> Decoder<'id> for bool
Accepts exactly the atoms true/false; every other term — including any
other atom — is WrongType.
Source§impl<'id> Decoder<'id> for f32
Reads as f64 and narrows; a magnitude beyond f32::MAX would round to
infinity, so it is rejected with FloatRange.
impl<'id> Decoder<'id> for f32
Reads as f64 and narrows; a magnitude beyond f32::MAX would round to
infinity, so it is rejected with FloatRange.
Source§impl<'id> Decoder<'id> for f64
Reads a float term (enif_get_double); an Erlang float is always finite, so
this never fails on range. WrongType if not a float.
impl<'id> Decoder<'id> for f64
Reads a float term (enif_get_double); an Erlang float is always finite, so
this never fails on range. WrongType if not a float.
Source§impl<'id> Decoder<'id> for i8
Reads the integer as i64, then narrows with a range check —
IntegerOverflow if it does not fit.
impl<'id> Decoder<'id> for i8
Reads the integer as i64, then narrows with a range check —
IntegerOverflow if it does not fit.
Source§impl<'id> Decoder<'id> for i16
Reads the integer as i64, then narrows with a range check —
IntegerOverflow if it does not fit.
impl<'id> Decoder<'id> for i16
Reads the integer as i64, then narrows with a range check —
IntegerOverflow if it does not fit.
Source§impl<'id> Decoder<'id> for i32
Reads the integer as i64, then narrows with a range check —
IntegerOverflow if it does not fit.
impl<'id> Decoder<'id> for i32
Reads the integer as i64, then narrows with a range check —
IntegerOverflow if it does not fit.
Source§impl<'id> Decoder<'id> for i64
Reads via enif_get_int64; the only failure is a bignum too wide for the
64-bit read (IntegerOverflow).
impl<'id> Decoder<'id> for i64
Reads via enif_get_int64; the only failure is a bignum too wide for the
64-bit read (IntegerOverflow).
Source§impl<'id> Decoder<'id> for isize
Reads as i64 and range-checks into isize
(IntegerOverflow if it does not fit).
impl<'id> Decoder<'id> for isize
Reads as i64 and range-checks into isize
(IntegerOverflow if it does not fit).
Source§impl<'id> Decoder<'id> for u8
Reads the integer as u64, then narrows with a range check —
IntegerOverflow on overflow or a
negative value.
impl<'id> Decoder<'id> for u8
Reads the integer as u64, then narrows with a range check —
IntegerOverflow on overflow or a
negative value.
Source§impl<'id> Decoder<'id> for u16
Reads the integer as u64, then narrows with a range check —
IntegerOverflow on overflow or a
negative value.
impl<'id> Decoder<'id> for u16
Reads the integer as u64, then narrows with a range check —
IntegerOverflow on overflow or a
negative value.
Source§impl<'id> Decoder<'id> for u32
Reads the integer as u64, then narrows with a range check —
IntegerOverflow on overflow or a
negative value.
impl<'id> Decoder<'id> for u32
Reads the integer as u64, then narrows with a range check —
IntegerOverflow on overflow or a
negative value.
Source§impl<'id> Decoder<'id> for u64
Reads via enif_get_uint64; fails with
IntegerOverflow on a negative value or a
bignum too wide for the 64-bit read.
impl<'id> Decoder<'id> for u64
Reads via enif_get_uint64; fails with
IntegerOverflow on a negative value or a
bignum too wide for the 64-bit read.
Source§impl<'id> Decoder<'id> for usize
Reads as u64 and range-checks into usize
(IntegerOverflow on a negative value or
overflow).
impl<'id> Decoder<'id> for usize
Reads as u64 and range-checks into usize
(IntegerOverflow on a negative value or
overflow).
Implementors§
impl<'id, T: Resource> Decoder<'id> for ResourceArc<T>
impl<'id> Decoder<'id> for AnyTerm<'id>
The identity decode — any term decodes to itself.
impl<'id> Decoder<'id> for Atom
Accepts an atom (enif_is_atom); WrongType
otherwise.
impl<'id> Decoder<'id> for BigInt
bigint only.Reads any integer term, however wide, via Integer::to_bigint. A
non-integer term is WrongType.
impl<'id> Decoder<'id> for Binary<'id>
impl<'id> Decoder<'id> for Bitstring<'id>
impl<'id> Decoder<'id> for Float<'id>
Accepts a float term (enif_term_type == Float); WrongType
otherwise.
impl<'id> Decoder<'id> for Fun<'id>
Accepts a fun (enif_is_fun); WrongType otherwise.
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 List<'id>
Accepts a list — including the empty list, and improper lists (enif_is_list).
WrongType otherwise.
impl<'id> Decoder<'id> for LocalPid
Accepts a node-local pid (enif_get_local_pid); an external (remote-node)
pid is rejected as WrongType.
impl<'id> Decoder<'id> for LocalPort
Accepts a node-local port; an external port is rejected as
WrongType.
impl<'id> Decoder<'id> for Map<'id>
Accepts a map (enif_is_map); WrongType otherwise.
impl<'id> Decoder<'id> for Pid<'id>
impl<'id> Decoder<'id> for Port<'id>
impl<'id> Decoder<'id> for Reference<'id>
Accepts a reference (enif_is_ref); WrongType
otherwise.
impl<'id> Decoder<'id> for Tuple<'id>
Accepts a tuple of any arity (enif_is_tuple);
WrongType otherwise.
impl<'id> Decoder<'id> for TypedTerm<'id>
Resolves the term to its TypedTerm variant (one enif_term_type call).
A type code this otter build does not recognize — a term type from a newer
OTP — is UnknownTermType.