Applicable

Trait Applicable 

Source
pub trait Applicable: Sized {
    type Base;

    // Required methods
    fn apply_to(self, base: &mut Self::Base);
    fn apply_to_opt(self, other: &mut Self);
    fn can_convert(&self) -> bool;

    // Provided methods
    fn build(self, base: Self::Base) -> Self::Base { ... }
    fn apply(self, other: Self) -> Self { ... }
}
Expand description

The trait is implemented for every generated structure. Thanks to this, you can use optional_struct in generic contexts. You should never have to implement this manually.

Required Associated Types§

Source

type Base

This is the type the optional_struct macro was used on. We need the type to be able to generate methods generating such structures.

Required Methods§

Source

fn apply_to(self, base: &mut Self::Base)

Similar to Applicable::build, but takes the Base by reference.

Source

fn apply_to_opt(self, other: &mut Self)

Applies the fields of this structure to another optional_struct. The fields on the “left” (from self) are applied iff they are set. E.g.: self.a == Some(Foo) and other.a == Some(Bar) => other.a == Some(Foo) self.a == None and other.a == Some(Bar) => other.a == Some(Bar) (where the arrow means, after calling this function) This function is also called recursively, and supports nested structures.

Source

fn can_convert(&self) -> bool

Signals whether the optional_struct has all its fields set to convert it to a Base. i.e. self.can_convert() == Base::try_from(self).is_ok()

Provided Methods§

Source

fn build(self, base: Self::Base) -> Self::Base

This function applies all the fields set in this structure to an instance of its Base. Note that this works recursively, enabling the use of nested optional_struct structures.

Source

fn apply(self, other: Self) -> Self

Similar to apply_to_opt but the argument other is applied to self. This allows chaining calls.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§