pub trait CitizenField: Sized {
// Required methods
fn encode_field(&self) -> Expr;
fn decode_field_expr(expr: &Expr, field: &'static str) -> Result<Self>;
// Provided method
fn decode_field_value(
cx: &mut Cx,
value: Value,
field: &'static str,
) -> Result<Self> { ... }
}Expand description
Encodes and decodes a Rust type as one citizen constructor field.
Generated and hand-written citizens use this trait to project each field to
an Expr for the constructor encoding and to recover it on read-construct.
The kernel owns Expr/Value/Cx; sim-citizen provides the field codec
and the standard scalar/collection implementations.
§Examples
The expr-level encode/decode pair round-trips without a context:
let original: Vec<i64> = vec![1, 2, 3];
let expr = original.encode_field();
let decoded = Vec::<i64>::decode_field_expr(&expr, "numbers").unwrap();
assert_eq!(decoded, original);Required Methods§
Sourcefn encode_field(&self) -> Expr
fn encode_field(&self) -> Expr
Encodes the field value as its constructor Expr.
Sourcefn decode_field_expr(expr: &Expr, field: &'static str) -> Result<Self>
fn decode_field_expr(expr: &Expr, field: &'static str) -> Result<Self>
Decodes the field from a constructor Expr, naming field in errors.
Provided Methods§
Sourcefn decode_field_value(
cx: &mut Cx,
value: Value,
field: &'static str,
) -> Result<Self>
fn decode_field_value( cx: &mut Cx, value: Value, field: &'static str, ) -> Result<Self>
Decodes the field from a runtime Value via its Expr projection.
Default implementation projects value to an Expr through cx and
delegates to CitizenField::decode_field_expr.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".