pub trait ValueStorage<T>: ComponentValueStoragePolicy {
type Storage;
// Required methods
fn present(value: T) -> Self::Storage;
fn present_unless_default(value: T, default: T) -> Self::Storage
where T: PartialEq;
fn map_into_value<Output, Present, Missing>(
storage: Self::Storage,
present: Present,
missing: Missing,
) -> Output
where Present: FnOnce(T) -> Output,
Missing: FnOnce() -> Output;
fn try_map_into_value<Output, Error, Present>(
storage: Self::Storage,
present: Present,
missing: Error,
) -> Result<Output, Error>
where Present: FnOnce(T) -> Output;
fn map_present_cloned<Output, Present>(
storage: &Self::Storage,
present: Present,
) -> Option<Output>
where T: Clone,
Present: FnOnce(T) -> Output;
fn is_present(storage: &Self::Storage) -> bool;
}Expand description
Storage behavior used by generated form value holders.
This lets #[derive(GpuiForm)] defer the T vs Option<T> choice to the
component shape that owns the policy while emitting concrete holder
conversion code.
Required Associated Types§
Required Methods§
Sourcefn present_unless_default(value: T, default: T) -> Self::Storagewhere
T: PartialEq,
fn present_unless_default(value: T, default: T) -> Self::Storagewhere
T: PartialEq,
Construct storage from a present form value, allowing RequiredValueStorage to
encode a value equal to the declared default as missing.
Sourcefn map_into_value<Output, Present, Missing>(
storage: Self::Storage,
present: Present,
missing: Missing,
) -> Output
fn map_into_value<Output, Present, Missing>( storage: Self::Storage, present: Present, missing: Missing, ) -> Output
Convert storage into an output value, using missing only for policies
that can represent missing values.
Sourcefn try_map_into_value<Output, Error, Present>(
storage: Self::Storage,
present: Present,
missing: Error,
) -> Result<Output, Error>where
Present: FnOnce(T) -> Output,
fn try_map_into_value<Output, Error, Present>(
storage: Self::Storage,
present: Present,
missing: Error,
) -> Result<Output, Error>where
Present: FnOnce(T) -> Output,
Fallible variant of ValueStorage::map_into_value.
Sourcefn map_present_cloned<Output, Present>(
storage: &Self::Storage,
present: Present,
) -> Option<Output>
fn map_present_cloned<Output, Present>( storage: &Self::Storage, present: Present, ) -> Option<Output>
Clone and map a present value, returning None only for policies that
can represent missing values.
Sourcefn is_present(storage: &Self::Storage) -> bool
fn is_present(storage: &Self::Storage) -> bool
Return whether storage contains a source value.
Generated validation uses this to make shape-owned requiredness visible
to validate() without hard-coding whether the policy stores Option<T>
or T.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".