Std.Dynamic
Dynamic
Section titled “Dynamic”enum DynamicA value in no particular format: what a format such as JSON parses into and writes from.
NullBool(Bool)Number(Number)Text(String)Items(List[Dynamic])Fields(Map[String, Dynamic])Binary(Bytes)
Segment
Section titled “Segment”enum SegmentA step of a path into a Dynamic: the key of Fields or the position of Items.
Key(String)Index(Int)
DecodeError
Section titled “DecodeError”error DecodeError(expected: String, actual: Dynamic, path: List[Segment])A Dynamic that could not be read as expected. path leads from the value being decoded to
actual. Show writes the kind of actual, not its contents.
expected: Stringactual: Dynamicpath: List[Segment]
Encode
Section titled “Encode”trait EncodeTurns a value into a Dynamic. Derivable ([trait.derive]).
-
fn to_dynamic(self: Self) -> DynamicThe value as a Dynamic.
-
fn to_field(self: Self) -> Option[Dynamic]The value written for a field of an object. None leaves the key out.
DecodeErrors
Section titled “DecodeErrors”error DecodeErrors(errors: List[DecodeError])Every failure of from_dynamic_all, in the order the parts were read. Never empty.
errors: List[DecodeError]
Decode
Section titled “Decode”trait DecodeBuilds a value from a Dynamic. Derivable, except for opaque types ([trait.derive]).
-
fn from_dynamic(d: Dynamic) -> Self fails DecodeErrorReads
d, stopping at the first failure. -
fn from_dynamic_all(d: Dynamic) -> Self fails DecodeErrorsReads like
from_dynamic, but reads every part and fails with all the failures. An impl that only writesfrom_dynamicstops at its first failure, which this wraps. -
fn from_absent() -> Self fails DecodeErrorThe value of a field whose key is missing. The default reads the key as null.
Attempt
Section titled “Attempt”enum Attempt[A]The result of reading one part while collecting failures.
Decoded(A)Failed(List[DecodeError])
ObjectKey
Section titled “ObjectKey”trait ObjectKey: OrdThe keys of a Map written as Fields.
-
fn to_key(self: Self) -> StringThe key as a String.
-
fn from_key(key: String) -> Self fails DecodeErrorReads a key written by
to_key.
fn kind(value: Dynamic) -> StringThe kind of value: "null", "bool", "number", "text", "items", "fields" or
"binary".
string
Section titled “string”fn string(value: Dynamic) -> String fails DecodeErrorReads Text as a String.
fn bytes(value: Dynamic) -> Bytes fails DecodeErrorReads Binary as Bytes.
fn bool(value: Dynamic) -> Bool fails DecodeErrorReads a Bool.
fn int(value: Dynamic) -> Int fails DecodeErrorReads a number as an Int. Its value must be an integer in the range of Int; 1.0 and 1e3
are read.
fn int64(value: Dynamic) -> Int64 fails DecodeErrorReads a number as an Int64. Its value must be an integer in the range of Int64; 1.0 and 1e3
are read.
fn float(value: Dynamic) -> Float fails DecodeErrorReads a number as the nearest Float.
fn list[A](item: fn(Dynamic) -> A fails DecodeError uses { R(item) }) -> fn(Dynamic) -> List[A] fails DecodeError uses { R(item) }A decoder that reads Items, each element by item.
optional
Section titled “optional”fn optional[A](decoder: fn(Dynamic) -> A fails DecodeError uses { R(decoder) }) -> fn(Dynamic) -> Option[A] fails DecodeError uses { R(decoder) }A decoder that reads Null as None and any other value as Some of decoder.
fn dict[V](value: fn(Dynamic) -> V fails DecodeError uses { R(value) }) -> fn(Dynamic) -> Map[String, V] fails DecodeError uses { R(value) }A decoder that reads Fields, each value by value.
fn index[A](n: Int, decoder: fn(Dynamic) -> A fails DecodeError uses { R(decoder) }) -> fn(Dynamic) -> A fails DecodeError uses { R(decoder) }A decoder that reads the element n of Items by decoder. Fewer elements is a DecodeError.
fn field[A](value: Dynamic, name: String, decoder: fn(Dynamic) -> A fails DecodeError uses { R(decoder) }) -> A fails DecodeError uses { R(decoder) }Reads the key name of Fields by decoder. A missing key is read as Null.
lookup
Section titled “lookup”fn lookup(value: Dynamic, name: String) -> Option[Dynamic] fails DecodeErrorThe value of the key name of Fields, or None if the key is missing.
fn items(value: Dynamic, n: Int) -> List[Dynamic] fails DecodeErrorThe elements of Items that has exactly n elements.
attempt
Section titled “attempt”fn attempt[A](f: fn() -> A fails DecodeErrors uses { R(f) }) -> Attempt[A] uses { R(f) }The value of f, or its failures instead of failing.
errors_of
Section titled “errors_of”fn errors_of[A](a: Attempt[A]) -> List[DecodeError]The failures of a: empty when it was decoded.
field_all
Section titled “field_all”fn field_all[A](value: Dynamic, name: String, decoder: fn(Dynamic) -> A fails DecodeErrors uses { R(decoder) }) -> A fails DecodeErrors uses { R(decoder) }field for a decoder that fails with every failure. name is added in front of the path of
each.
index_all
Section titled “index_all”fn index_all[A](n: Int, decoder: fn(Dynamic) -> A fails DecodeErrors uses { R(decoder) }) -> fn(Dynamic) -> A fails DecodeErrors uses { R(decoder) }index for a decoder that fails with every failure.
fn tag(value: Dynamic) -> String fails DecodeErrorThe "tag" of an enum written by Encode.
object
Section titled “object”fn object(fields: List[(String, Dynamic)]) -> DynamicFields of fields. For a repeated key, the later value.
variant
Section titled “variant”fn variant(tag: String, value: Option[Dynamic]) -> DynamicThe form of an enum written by Encode: an object with the "tag", and the "value" if there
is one.