Skip to main content

ValueStorage

Trait ValueStorage 

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

Source

type Storage

Concrete generated value-holder field storage.

Required Methods§

Source

fn present(value: T) -> Self::Storage

Construct storage from a present form value.

Source

fn present_unless_default(value: T, default: T) -> Self::Storage
where T: PartialEq,

Construct storage from a present form value, allowing RequiredValueStorage to encode a value equal to the declared default as missing.

Source

fn map_into_value<Output, Present, Missing>( storage: Self::Storage, present: Present, missing: Missing, ) -> Output
where Present: FnOnce(T) -> Output, Missing: FnOnce() -> Output,

Convert storage into an output value, using missing only for policies that can represent missing values.

Source

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.

Source

fn map_present_cloned<Output, Present>( storage: &Self::Storage, present: Present, ) -> Option<Output>
where T: Clone, Present: FnOnce(T) -> Output,

Clone and map a present value, returning None only for policies that can represent missing values.

Source

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".

Implementors§