pub trait Refineable: Clone {
type Refinement: Refineable<Refinement = Self::Refinement> + IsEmpty + Default;
// Required methods
fn refine(&mut self, refinement: &Self::Refinement);
fn refined(self, refinement: Self::Refinement) -> Self;
fn is_superset_of(&self, refinement: &Self::Refinement) -> bool;
fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement;
// Provided method
fn from_cascade(cascade: &Cascade<Self>) -> Self
where Self: Sized + Default { ... }
}Expand description
A trait for types that can be refined with partial updates.
The Refineable trait enables hierarchical configuration patterns where a base configuration
can be selectively overridden by refinements. This is particularly useful for styling and
settings, and theme hierarchies.
§Derive Macro
The #[derive(Refineable)] macro automatically generates a companion refinement type and
implements this trait. For a struct Style, it creates StyleRefinement where each field is
wrapped appropriately:
- Refineable fields (marked with
#[refineable]): Become the corresponding refinement type (e.g.,BarbecomesBarRefinement) - Optional fields (
Option<T>): Remain asOption<T> - Regular fields: Become
Option<T>
§Attributes
The derive macro supports these attributes on the struct:
#[refineable(Debug)]: ImplementsDebugfor the refinement type#[refineable(Serialize)]: DerivesSerializewhich skips serializingNone#[refineable(OtherTrait)]: Derives additional traits on the refinement type
Fields can be marked with:
#[refineable]: Field is itself refineable (uses nested refinement type)
Required Associated Types§
type Refinement: Refineable<Refinement = Self::Refinement> + IsEmpty + Default
Required Methods§
Sourcefn refine(&mut self, refinement: &Self::Refinement)
fn refine(&mut self, refinement: &Self::Refinement)
Applies the given refinement to this instance, modifying it in place.
Only non-empty values in the refinement are applied.
- For refineable fields, this recursively calls
refine. - For other fields, the value is replaced if present in the refinement.
Sourcefn refined(self, refinement: Self::Refinement) -> Self
fn refined(self, refinement: Self::Refinement) -> Self
Returns a new instance with the refinement applied, equivalent to cloning self and calling
refine on it.
Sourcefn is_superset_of(&self, refinement: &Self::Refinement) -> bool
fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
Returns true if this instance would contain all values from the refinement.
For refineable fields, this recursively checks is_superset_of. For other fields, this
checks if the refinement’s Some values match this instance’s values.
Sourcefn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
Returns a refinement that represents the difference between this instance and the given refinement.
For refineable fields, this recursively calls subtract. For other fields, the field is
None if the field’s value is equal to the refinement.
Provided Methods§
Sourcefn from_cascade(cascade: &Cascade<Self>) -> Self
fn from_cascade(cascade: &Cascade<Self>) -> Self
Creates an instance from a cascade by merging all refinements atop the default value.
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.