apply/boundary

Types

Typed version of the current runtime.

Usage: case platform() { OnErlang -> ...; OnJavascript -> ... } — pattern match instead of comparing platform_name() strings. Note: like platform_name(), this comes from a runtime external; an unknown runtime falls back to OnJavascript (in practice only these two targets exist).

pub type Platform {
  OnErlang
  OnJavascript
}

Constructors

  • OnErlang
  • OnJavascript

Values

pub fn debug_string(value: any) -> String

Renders any value as a readable string, for error messages.

Usage: debug_string(value) to show a raw value in an error message. Note: the representation differs per runtime (e.g. a string is "x" on js and <<"x">> on erl); large objects or cycles fall back to String(value) / ~p.

pub fn identify(value: any) -> #(String, any)

Detects the runtime type of any value, returning #(type_tag, original_value).

Usage: identify(value); tags are "bool" / "int" / "float" / "string" / "bit_array" / "list" / "dict" / "nil" / "tuple" / "function", plus "atom" on Erlang; anything else is "local". Note: tags are mostly aligned, but with inherent differences — on Erlang String and BitArray are both binary, and a valid-UTF-8 binary is tagged "string"; on JavaScript they are distinct types.

pub fn is_function(func: function) -> Bool

Returns whether a value is a function.

Usage: is_function(fn(x) { x }). Note: on Erlang a {function, M, F} tuple also counts as a function; that marker form is reserved for this function.

pub fn is_tuple(any: tuple) -> Bool

Returns whether a value is a tuple.

Usage: is_tuple(#(1, 2)); the parameter is untyped, but only tuples return True. Note: on JavaScript a tuple is an array, so any JS array is treated as a tuple.

pub fn platform() -> Platform

See Platform. Wraps platform_name() and collapses the string into a constructor.

Usage: platform(). Note: anything other than "erlang" is treated as OnJavascript.

pub fn platform_name() -> String

The current runtime platform.

Returns "erlang" on the Erlang target and "javascript" on the JavaScript target.

pub fn to_custom_type(any: any) -> custom_type

Identity cast: “marks” any value as the requested type, including opaque types.

Usage: to_custom_type(raw) to get a generic a from a runtime raw value. Note: performs no check or conversion at runtime; it is a pure type-level assertion, and misuse breaks type safety.

pub fn try_catch_ffi(func: e, args: tupled_args) -> a

Runs func(args) and captures exceptions (FFI primitive, not meant to be used directly).

Usage: called by the try_catch wrappers in apply/js and apply/erl. Note: the exact success/failure shape differs per runtime (js returns #(func, args, type, reason, stack); erl returns #(func, args, class, reason, stacktrace) with raw values); each side’s try_catch interprets and structures it.

pub fn tuple_size(tuple: tupled_args) -> Result(Int, Nil)

Returns the length of a tuple.

Usage: tuple_size(#(1, 2)). Note: returns Error(Nil) for non-tuples; on JavaScript arrays count as tuples.

✨ Search Document