pub struct Responsive<T> { /* private fields */ }Expand description
A breakpoint-aware value with inheritance from smaller tiers.
Each slot is Option<T>. Slot 0 (Xs) is always Some (enforced
by the constructor). Resolution walks downward from the requested
breakpoint until a Some slot is found.
Implementations§
Source§impl<T: Clone> Responsive<T>
impl<T: Clone> Responsive<T>
Sourcepub fn new(base: T) -> Self
pub fn new(base: T) -> Self
Create a responsive value with a base value for Xs.
All larger breakpoints inherit this value until explicitly overridden.
Sourcepub fn at(self, bp: Breakpoint, value: T) -> Self
pub fn at(self, bp: Breakpoint, value: T) -> Self
Set the value for a specific breakpoint (builder pattern).
Sourcepub fn set(&mut self, bp: Breakpoint, value: T)
pub fn set(&mut self, bp: Breakpoint, value: T)
Set the value for a specific breakpoint (mutating).
Sourcepub fn clear(&mut self, bp: Breakpoint)
pub fn clear(&mut self, bp: Breakpoint)
Clear the override for a specific breakpoint, reverting to inheritance.
Clearing Xs is a no-op (it always has a value).
Sourcepub fn resolve(&self, bp: Breakpoint) -> &T
pub fn resolve(&self, bp: Breakpoint) -> &T
Resolve the value for a given breakpoint.
Walks downward from bp to Xs until an explicit value is found.
Always succeeds because Xs is always set.
Sourcepub fn resolve_cloned(&self, bp: Breakpoint) -> T
pub fn resolve_cloned(&self, bp: Breakpoint) -> T
Resolve and clone the value for a given breakpoint.
Sourcepub fn has_explicit(&self, bp: Breakpoint) -> bool
pub fn has_explicit(&self, bp: Breakpoint) -> bool
Whether a specific breakpoint has an explicit (non-inherited) value.
Sourcepub fn explicit_values(&self) -> impl Iterator<Item = (Breakpoint, &T)>
pub fn explicit_values(&self) -> impl Iterator<Item = (Breakpoint, &T)>
Get all explicitly set breakpoints and their values.
Trait Implementations§
Source§impl<T: Clone> Clone for Responsive<T>
impl<T: Clone> Clone for Responsive<T>
Source§fn clone(&self) -> Responsive<T>
fn clone(&self) -> Responsive<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more