Skip to main content

FormBridge

Trait FormBridge 

Source
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 excluded

Required Methods§

Source

fn to_form_value(&self) -> Value

Converts the value into its exact Value representation.

Source

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

Source§

impl FormBridge for bool

Source§

impl FormBridge for f32

Source§

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.

Source§

fn from_validated(v: &Value) -> Option<Self>

Source§

impl FormBridge for f64

Source§

impl FormBridge for i8

Source§

impl FormBridge for i16

Source§

impl FormBridge for i32

Source§

impl FormBridge for i64

Source§

impl FormBridge for u8

Source§

impl FormBridge for u16

Source§

impl FormBridge for u32

Implementors§