Std. Beam
(Cure Standard Library v0.37.2)
View Source
Opaque native term at the foreign boundary. It can be passed to trusted primitives, but ordinary Cure code cannot inspect it or claim a type for it.
Examples
use Std.Beam
let encoded = to_beam(42)
decode_int(encoded) # => Ok(42)
adt_tag(to_beam(:ok)) # => Some(:ok)
Summary
Types
Why an inbound BEAM term could not be validated as the requested Cure type. Decoding is deliberately separate from encoding: outbound conversion is total, while a foreign term may have any tag or payload shape.
Callbacks
Fallible validation of an opaque foreign term. Implementations are explicit until structural decoder derivation can prove every field recursively.
Total translation of a typed Cure value to its native BEAM representation. ADTs receive an automatically-derived implementation unless their owner supplies a hand-written implementation.
Functions
Return the constructor field count of an ADT-shaped BEAM term (0 for a
nullary atom, size - 1 for a tagged tuple), or None() otherwise.
Native ADTs use an atom for a nullary constructor and a tuple whose first element is the constructor atom otherwise. These observations expose only the validated tag and field count; structural decoders still validate and reconstruct every field before producing a typed value.
Total inbound observations. A projection is performed only after its BEAM guard succeeds, so no unvalidated RawTerm is claimed as a Cure value.
Validate term as a BEAM atom, returning Error(InvalidBeamTerm()) otherwise.
Validate term as a BEAM boolean, returning Error(InvalidBeamTerm()) otherwise.
Validate term as a BEAM float, returning Error(InvalidBeamTerm()) otherwise.
Validate term as a BEAM integer, returning Error(InvalidBeamTerm()) otherwise.
Validate term as a BEAM PID, returning Error(InvalidBeamTerm()) otherwise.
A BEAM binary is not a Cure String: String is nominal and erases to
{String, code_points}. Decode the UTF-8 binary into its code points and
rebuild the nominal value, rather than relabelling the binary.
The primitive boundary used by derived and hand-written encoders. raw_term
is an erasing identity at runtime; the tuple merely prevents an unconstrained
polymorphic extern from manufacturing RawTerm in Core.
Extract a BarePid from term if it is a BEAM PID, or None() otherwise.
Return Some(size) if term is a BEAM tuple, or None() otherwise.
Zero-based checked tuple access for Cure callers; Erlang's element/2 is one-based. Negative and out-of-range indices return None.
Types
type BarePid
type BeamDecodeError
Why an inbound BEAM term could not be validated as the requested Cure type. Decoding is deliberately separate from encoding: outbound conversion is total, while a foreign term may have any tag or payload shape.
type BeamTerm
type EncodedTerm
Callbacks
interface BeamDecode(t)
Fallible validation of an opaque foreign term. Implementations are explicit until structural decoder derivation can prove every field recursively.
interface BeamEncode(t)
Total translation of a typed Cure value to its native BEAM representation. ADTs receive an automatically-derived implementation unless their owner supplies a hand-written implementation.
Functions
fn adt_arity(term: BeamTerm) -> Option(Int)
Return the constructor field count of an ADT-shaped BEAM term (0 for a
nullary atom, size - 1 for a tagged tuple), or None() otherwise.
fn adt_tag(term: BeamTerm) -> Option(Atom)
Native ADTs use an atom for a nullary constructor and a tuple whose first element is the constructor atom otherwise. These observations expose only the validated tag and field count; structural decoders still validate and reconstruct every field before producing a typed value.
fn atom(term: BeamTerm) -> Option(Atom)
Total inbound observations. A projection is performed only after its BEAM guard succeeds, so no unvalidated RawTerm is claimed as a Cure value.
fn decode_atom(term: BeamTerm) -> Result(Atom, BeamDecodeError)
Validate term as a BEAM atom, returning Error(InvalidBeamTerm()) otherwise.
fn decode_bool(term: BeamTerm) -> Result(Bool, BeamDecodeError)
Validate term as a BEAM boolean, returning Error(InvalidBeamTerm()) otherwise.
fn decode_float(term: BeamTerm) -> Result(Float, BeamDecodeError)
Validate term as a BEAM float, returning Error(InvalidBeamTerm()) otherwise.
fn decode_int(term: BeamTerm) -> Result(Int, BeamDecodeError)
Validate term as a BEAM integer, returning Error(InvalidBeamTerm()) otherwise.
fn decode_pid(term: BeamTerm) -> Result(BarePid, BeamDecodeError)
Validate term as a BEAM PID, returning Error(InvalidBeamTerm()) otherwise.
fn decode_string(term: BeamTerm) -> Result(String, BeamDecodeError)
A BEAM binary is not a Cure String: String is nominal and erases to
{String, code_points}. Decode the UTF-8 binary into its code points and
rebuild the nominal value, rather than relabelling the binary.
fn forget(a: Type, value: a) -> BeamTerm
The primitive boundary used by derived and hand-written encoders. raw_term
is an erasing identity at runtime; the tuple merely prevents an unconstrained
polymorphic extern from manufacturing RawTerm in Core.
fn from_beam(term: BeamTerm) -> Result(t, BeamDecodeError)
fn pid(term: BeamTerm) -> Option(BarePid)
Extract a BarePid from term if it is a BEAM PID, or None() otherwise.
fn to_beam(value: t) -> EncodedTerm
fn tuple_arity(term: BeamTerm) -> Option(Int)
Return Some(size) if term is a BEAM tuple, or None() otherwise.
fn tuple_element(term: BeamTerm, index: Int) -> Option(BeamTerm)
Zero-based checked tuple access for Cure callers; Erlang's element/2 is one-based. Negative and out-of-range indices return None.