pedantic/encode
Types
An Encoder describes how to serialize a domain value back to Dynamic.
pub type Encoder(t) {
Encoder(
graph: report.TypeGraph,
function: fn(t) -> dynamic.Dynamic,
)
}
Constructors
-
Encoder( graph: report.TypeGraph, function: fn(t) -> dynamic.Dynamic, )
An intermediate builder structure used to construct record encoders.
pub opaque type ObjectBuilder(value)
Values
pub fn build(builder: ObjectBuilder(value)) -> Encoder(value)
Finalizes the ObjectBuilder, converting it into a full Encoder.
pub fn describe(encoder: Encoder(t), desc: String) -> Encoder(t)
Sets the description metadata in the AST graph.
pub fn dict(
value_encoder: Encoder(a),
) -> Encoder(dict.Dict(String, a))
Dict combinator to encode dictionaries to dynamic objects.
pub fn example(
encoder: Encoder(t),
ex: dynamic.Dynamic,
) -> Encoder(t)
Sets the example metadata in the AST graph.
pub fn field(
builder: ObjectBuilder(value),
name: String,
field_encoder: Encoder(field_type),
get: fn(value) -> field_type,
) -> ObjectBuilder(value)
Applies a field description, encoder, and getter to the object builder.
pub fn list(element_encoder: Encoder(a)) -> Encoder(List(a))
List combinator to encode lists to dynamic arrays.
pub fn object(name: String) -> ObjectBuilder(value)
Initializes an ObjectBuilder for a custom record constructor.
pub fn optional(
inner_encoder: Encoder(a),
) -> Encoder(option.Option(a))
Option/Optional combinator representing absent or nullable values.