pub struct Measurement {
pub minimum: usize,
pub maximum: usize,
}Expand description
The minimum and maximum width requirements of a renderable.
Fields§
§minimum: usizeMinimum width required (content won’t fit in less).
maximum: usizeMaximum width the content would use if given unlimited space.
Implementations§
Source§impl Measurement
impl Measurement
Sourcepub fn exact(width: usize) -> Self
pub fn exact(width: usize) -> Self
Create a measurement with both min and max set to the same value.
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Normalize the measurement ensuring minimum <= maximum and both >= 0.
Since we use usize, values are always >= 0, but this ensures
the minimum does not exceed the maximum.
§Examples
use rich_rs::Measurement;
// Inverted measurement gets corrected
let m = Measurement::new(50, 10);
let normalized = m.normalize();
assert_eq!(normalized.minimum, 10);
assert_eq!(normalized.maximum, 10);Sourcepub fn with_maximum(&self, width: usize) -> Self
pub fn with_maximum(&self, width: usize) -> Self
Get a measurement where both widths are <= the given width.
§Examples
use rich_rs::Measurement;
let m = Measurement::new(10, 50);
let constrained = m.with_maximum(30);
assert_eq!(constrained.minimum, 10);
assert_eq!(constrained.maximum, 30);
// When width is less than minimum, both get clamped
let m = Measurement::new(20, 50);
let constrained = m.with_maximum(15);
assert_eq!(constrained.minimum, 15);
assert_eq!(constrained.maximum, 15);Sourcepub fn with_minimum(&self, width: usize) -> Self
pub fn with_minimum(&self, width: usize) -> Self
Get a measurement where both widths are >= the given width.
§Examples
use rich_rs::Measurement;
let m = Measurement::new(10, 50);
let constrained = m.with_minimum(20);
assert_eq!(constrained.minimum, 20);
assert_eq!(constrained.maximum, 50);
// When width is greater than maximum, both get raised
let m = Measurement::new(10, 30);
let constrained = m.with_minimum(40);
assert_eq!(constrained.minimum, 40);
assert_eq!(constrained.maximum, 40);Sourcepub fn clamp_bounds(
&self,
min_width: Option<usize>,
max_width: Option<usize>,
) -> Self
pub fn clamp_bounds( &self, min_width: Option<usize>, max_width: Option<usize>, ) -> Self
Clamp the measurement within optional min and max bounds.
This clamps the measurement itself (both minimum and maximum fields),
not a width value. Use clamp_width to clamp a width within measurement bounds.
§Examples
use rich_rs::Measurement;
let m = Measurement::new(10, 50);
// Clamp with both bounds
let clamped = m.clamp_bounds(Some(15), Some(40));
assert_eq!(clamped.minimum, 15);
assert_eq!(clamped.maximum, 40);
// Clamp with only max bound
let clamped = m.clamp_bounds(None, Some(30));
assert_eq!(clamped.minimum, 10);
assert_eq!(clamped.maximum, 30);
// Clamp with only min bound
let clamped = m.clamp_bounds(Some(20), None);
assert_eq!(clamped.minimum, 20);
assert_eq!(clamped.maximum, 50);Sourcepub fn clamp_width(&self, width: usize) -> usize
pub fn clamp_width(&self, width: usize) -> usize
Clamp a width value to within the measurement bounds.
Returns a width that is >= minimum and <= maximum.
§Panics
Panics if the measurement invariant is violated (i.e., minimum > maximum).
In debug builds, a debug_assert! provides a clearer error message.
Use normalize to fix invalid measurements before
calling this method.
§Examples
use rich_rs::Measurement;
let m = Measurement::new(10, 50);
assert_eq!(m.clamp_width(5), 10); // Below minimum
assert_eq!(m.clamp_width(30), 30); // Within bounds
assert_eq!(m.clamp_width(100), 50); // Above maximumSourcepub fn union(&self, other: &Measurement) -> Self
pub fn union(&self, other: &Measurement) -> Self
Combine with another measurement, taking the max of mins and maxes.
Sourcepub fn from_segments(segments: &Segments) -> Self
pub fn from_segments(segments: &Segments) -> Self
Create a measurement from rendered segments.
This is the default measurement strategy: render and measure the result. The minimum is the longest word, maximum is the total width.
Note: This method assumes single-line content. For multi-line content, the maximum will include the total width of all lines combined rather than the width of the widest line. Handle multi-line content by splitting into lines first and taking the union of per-line measurements.
Trait Implementations§
Source§impl Clone for Measurement
impl Clone for Measurement
Source§fn clone(&self) -> Measurement
fn clone(&self) -> Measurement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Measurement
impl Debug for Measurement
Source§impl Default for Measurement
impl Default for Measurement
Source§fn default() -> Measurement
fn default() -> Measurement
Source§impl PartialEq for Measurement
impl PartialEq for Measurement
impl Copy for Measurement
impl Eq for Measurement
impl StructuralPartialEq for Measurement
Auto Trait Implementations§
impl Freeze for Measurement
impl RefUnwindSafe for Measurement
impl Send for Measurement
impl Sync for Measurement
impl Unpin for Measurement
impl UnwindSafe for Measurement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.