kata/schema
Types
Values
pub fn coerce_bool() -> Schema(Bool)
Bool schema that also accepts VString “true”/“false”.
pub fn coerce_float() -> Schema(Float)
Float schema that also accepts VString parseable as float, or VInt.
pub fn coerce_int() -> Schema(Int)
Int schema that also accepts VString parseable as integer.
pub fn decode(
schema: Schema(a),
value: value.Value,
) -> Result(a, List(error.Error))
Decode a Value into a typed value using the schema
pub fn encode(schema: Schema(a), value: a) -> value.Value
Encode a typed value into a Value using the schema
pub fn field(
key: String,
field_schema: Schema(a),
get: fn(final) -> a,
next: fn(a) -> Schema(final),
) -> Schema(final)
Define a field in an object schema.
- key: field name
- field_schema: schema for the field value
- get: extract field from the final record (for encode)
- next: continuation receiving the decoded field value
pub fn from_bool(
schema: Schema(a),
value: Bool,
) -> Result(a, List(error.Error))
Construct a validated value from a Bool.
pub fn from_float(
schema: Schema(a),
value: Float,
) -> Result(a, List(error.Error))
Construct a validated value from a Float.
pub fn from_int(
schema: Schema(a),
value: Int,
) -> Result(a, List(error.Error))
Construct a validated value from an Int.
pub fn from_string(
schema: Schema(a),
value: String,
) -> Result(a, List(error.Error))
Construct a validated value from a String.
pub fn optional(inner: Schema(a)) -> Schema(option.Option(a))
pub fn optional_field(
key: String,
field_schema: Schema(a),
default: a,
get: fn(final) -> a,
next: fn(a) -> Schema(final),
) -> Schema(final)
Optional field with a default value when missing.
pub fn refine_float(
s: Schema(Float),
ref: ast.FloatRef,
check: fn(Float) -> Result(Float, List(error.Error)),
) -> Schema(Float)
Add a float refinement to a Schema(Float).
pub fn refine_int(
s: Schema(Int),
ref: ast.IntRef,
check: fn(Int) -> Result(Int, List(error.Error)),
) -> Schema(Int)
Add an int refinement to a Schema(Int).
pub fn refine_string(
s: Schema(String),
ref: ast.StringRef,
check: fn(String) -> Result(String, List(error.Error)),
) -> Schema(String)
Add a string refinement to a Schema(String).