Refineable

Trait Refineable 

Source
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., Bar becomes BarRefinement)
  • Optional fields (Option<T>): Remain as Option<T>
  • Regular fields: Become Option<T>

§Attributes

The derive macro supports these attributes on the struct:

  • #[refineable(Debug)]: Implements Debug for the refinement type
  • #[refineable(Serialize)]: Derives Serialize which skips serializing None
  • #[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§

Source

type Refinement: Refineable<Refinement = Self::Refinement> + IsEmpty + Default

Required Methods§

Source

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

fn refined(self, refinement: Self::Refinement) -> Self

Returns a new instance with the refinement applied, equivalent to cloning self and calling refine on it.

Source

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.

Source

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§

Source

fn from_cascade(cascade: &Cascade<Self>) -> Self
where Self: Sized + Default,

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.

Implementors§

Source§

impl Refineable for StrikethroughStyle

Source§

impl Refineable for StrikethroughStyleRefinement

Source§

impl Refineable for Style

Source§

impl Refineable for StyleRefinement

Source§

impl Refineable for TextStyle

Source§

impl Refineable for TextStyleRefinement

Source§

impl Refineable for UnderlineStyle

Source§

impl Refineable for UnderlineStyleRefinement

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Bounds<T>
where Option<Point<T>>: Clone, Option<Size<T>>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for BoundsRefinement<T>
where Option<Point<T>>: Clone, Option<Size<T>>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Corners<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for CornersRefinement<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Edges<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for EdgesRefinement<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Point<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for PointRefinement<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Size<T>
where Option<T>: Clone,

Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for SizeRefinement<T>
where Option<T>: Clone,