pub trait FormBridge: Sized {
// Required methods
fn to_form_value(&self) -> Value;
fn from_validated(v: &Value) -> Option<Self>;
}Expand description
Lossless Rust-value ↔ Value bridging used by generated typed parses:
to_form_value feeds the composed object
schema; from_validated reconstructs fields
from validated output. Total on validated outputs — returns None only on
an invariant breach or wrong-variant input.
§f32 narrowing precondition
For f32, narrowing in from_validated is sound
ONLY when the F64 input originated from
to_form_value of an f32 (the validated-output
precondition): the widening was lossless, so the inverse cast recovers the
exact original bits. Arbitrary F64 inputs NOT produced that way may be
truncated or rounded by the narrowing cast.
Implemented exactly for the v0 supported-type matrix (String, bool,
i8..i64, u8..u32, f32, f64). u64/usize are deliberately
excluded, mirroring the crate::value::ToValue fidelity rules (DV-1):
use formars_core::prelude::*;
fn require_bridge<T: formars_core::FormBridge>(_: &T) {}
require_bridge(&7u64); // u64/usize deliberately excludedRequired Methods§
Sourcefn to_form_value(&self) -> Value
fn to_form_value(&self) -> Value
Converts the value into its exact Value representation.
Sourcefn from_validated(v: &Value) -> Option<Self>
fn from_validated(v: &Value) -> Option<Self>
Reconstructs the value from a validated output; None when v does
not carry the exact variant/range this type round-trips as.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl FormBridge for String
impl FormBridge for String
fn to_form_value(&self) -> Value
fn from_validated(v: &Value) -> Option<Self>
Source§impl FormBridge for bool
impl FormBridge for bool
fn to_form_value(&self) -> Value
fn from_validated(v: &Value) -> Option<Self>
Source§impl FormBridge for f32
impl FormBridge for f32
Source§fn to_form_value(&self) -> Value
fn to_form_value(&self) -> Value
§Narrowing precondition
from_validated narrows F64 back to f32; this is sound ONLY when
the F64 originated from FormBridge::to_form_value of an f32
(validated output — the widening was lossless, so the exact original
bits are recovered). Arbitrary F64 inputs may truncate or round.