pub struct Lunit(/* private fields */);ui only.Expand description
▦ 🧱 📏 Fixed-point scalar used for UI layout negotiation.
📦 size_of::<Lunit>() == 4 bytes / 32 bits
⚗️Option<T> ❗🟰 T
Lunit is expressed in logical layout space. It is not a device pixel,
physical pixel, terminal cell, typographic point, or real-world length.
Backend projection maps it to physical pixels, terminal cells, or other output units.
Implementations§
Source§impl Lunit
impl Lunit
Sourcepub const CARRIER_BITS: u32 = i32::BITS
pub const CARRIER_BITS: u32 = i32::BITS
Number of bits in the primitive carrier.
Sourcepub const VALUE_BITS: u32
pub const VALUE_BITS: u32
Number of bits used by the signed payload.
Sourcepub const COUNT_BITS: u32
pub const COUNT_BITS: u32
Number of metadata bits used by the saturating boundary-event counter.
Sourcepub const IS_SYMMETRIC: bool = true
pub const IS_SYMMETRIC: bool = true
Whether the signed payload range is symmetric around zero.
Sourcepub const fn new_checked(value: i32) -> Option<Self> ⓘ
pub const fn new_checked(value: i32) -> Option<Self> ⓘ
Creates a value if it fits in the payload range.
Sourcepub const fn new_saturated(value: i32) -> Self
pub const fn new_saturated(value: i32) -> Self
Creates a value saturated to the payload range.
Sourcepub const fn new_saturated_up(value: i64) -> Self
pub const fn new_saturated_up(value: i64) -> Self
Creates a value saturated to the payload range, from an upcasted carrier.
Sourcepub const fn from_raw(raw: i32) -> Option<Self> ⓘ
pub const fn from_raw(raw: i32) -> Option<Self> ⓘ
Creates a value from a raw encoded carrier.
Returns None if raw is reserved, invalid for the underlying representation,
or decodes outside the payload range.
Non-canonical raw encodings with count == 0 are canonicalized so
the direction bit is cleared.
Sourcepub const fn is_bounded(self) -> bool
pub const fn is_bounded(self) -> bool
Returns whether this value carries at least one boundary event.
Sourcepub const fn bound_count(self) -> u32
pub const fn bound_count(self) -> u32
Returns the saturating boundary-event count.
A value of 0 means no boundary event is recorded. When this is 0,
bound_dir returns None.
Sourcepub const fn bound_dir(self) -> Option<Boundary1d> ⓘ
pub const fn bound_dir(self) -> Option<Boundary1d> ⓘ
Returns the last recorded boundary direction.
Returns None when bound_count is 0.
Sourcepub const fn clear_meta(self) -> Self
pub const fn clear_meta(self) -> Self
Returns the same payload value with empty metadata.
Sourcepub const fn with_bound_meta(self, count: u32, dir: Option<Boundary1d>) -> Self
pub const fn with_bound_meta(self, count: u32, dir: Option<Boundary1d>) -> Self
Returns the same payload value with explicit boundary metadata.
count saturates to MAX_COUNT.
When count == 0, dir is ignored
and the raw direction bit is canonicalized to zero.
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Whether the value is less than zero.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Whether the value is greater than zero.
Sourcepub const fn is_nonnegative(self) -> bool
pub const fn is_nonnegative(self) -> bool
Whether the value is greater than or equal to zero.
Sourcepub const fn is_nonpositive(self) -> bool
pub const fn is_nonpositive(self) -> bool
Whether the value is less than or equal to zero.
Sourcepub const fn max(self, other: Self) -> Self
pub const fn max(self, other: Self) -> Self
Returns the greater decoded value.
Metadata is cleared because the result is recomputed.
Sourcepub const fn max_meta(self, other: Self) -> Self
pub const fn max_meta(self, other: Self) -> Self
Returns the greater value, preserving the selected operand metadata.
Sourcepub const fn max_zero(self) -> Self
pub const fn max_zero(self) -> Self
Returns the decoded value floored at zero.
Metadata is cleared because the result is recomputed.
Sourcepub const fn max_zero_meta(self) -> Self
pub const fn max_zero_meta(self) -> Self
Returns the decoded value floored at zero, preserving selected metadata.
Sourcepub const fn min(self, other: Self) -> Self
pub const fn min(self, other: Self) -> Self
Returns the lesser decoded value.
Metadata is cleared because the result is recomputed.
Sourcepub const fn min_meta(self, other: Self) -> Self
pub const fn min_meta(self, other: Self) -> Self
Returns the lesser value, preserving the selected operand metadata.
Sourcepub const fn min_zero(self) -> Self
pub const fn min_zero(self) -> Self
Returns the decoded value capped at zero.
Metadata is cleared because the result is recomputed.
Sourcepub const fn min_zero_meta(self) -> Self
pub const fn min_zero_meta(self) -> Self
Returns the decoded value capped at zero, preserving selected metadata.
Sourcepub const fn clamp(self, min: Self, max: Self) -> Self
pub const fn clamp(self, min: Self, max: Self) -> Self
Clamps the decoded value between min and max.
Metadata is cleared because the result is recomputed.
If min > max, this returns min.
Sourcepub const fn clamp_meta(self, min: Self, max: Self) -> Self
pub const fn clamp_meta(self, min: Self, max: Self) -> Self
Clamps self between min and max, preserving selected metadata.
If min > max, this returns min.
Source§impl Lunit
impl Lunit
Sourcepub const QUANTA_PER_LOGICAL_PX: i32 = 120
pub const QUANTA_PER_LOGICAL_PX: i32 = 120
Number of internal layout quanta per logical UI pixel.
Sourcepub const fn px(px: i32) -> Self
pub const fn px(px: i32) -> Self
Creates a layout scalar from whole logical UI pixels.
Saturates if the scaled value escapes the payload range.
Sourcepub const fn px_frac(num: i32, den: i32) -> Self
pub const fn px_frac(num: i32, den: i32) -> Self
Creates a layout scalar from a fraction of a logical UI pixel.
Rounds to the nearest representable quantum and saturates on overflow.
Sourcepub const fn from_quanta(quanta: i32) -> Self
pub const fn from_quanta(quanta: i32) -> Self
Creates a layout scalar from internal layout quanta.
Sourcepub const fn positive_part(self) -> Self
pub const fn positive_part(self) -> Self
Returns this value clamped below by zero.
Sourcepub const fn sub_floor_zero(self, rhs: Self) -> Self
pub const fn sub_floor_zero(self, rhs: Self) -> Self
Subtracts rhs, returning zero instead of a negative result.
Sourcepub const fn div_floor_i32(self, rhs: i32) -> Self
pub const fn div_floor_i32(self, rhs: i32) -> Self
Divides by an integer, rounding toward negative infinity.
Saturates to the signed endpoint if rhs == 0.
Sourcepub const fn div_ceil_i32(self, rhs: i32) -> Self
pub const fn div_ceil_i32(self, rhs: i32) -> Self
Divides by an integer, rounding toward positive infinity.
Saturates to the signed endpoint if rhs == 0.
Sourcepub const fn div_round_i32(self, rhs: i32) -> Self
pub const fn div_round_i32(self, rhs: i32) -> Self
Divides by an integer, rounding to the nearest result.
Halfway cases round away from zero. Saturates to the signed endpoint
if rhs == 0.
Sourcepub const fn split_floor(self, parts: i32) -> Self
pub const fn split_floor(self, parts: i32) -> Self
Returns the base part size when splitting this value into parts.
Returns zero if parts <= 0.
Sourcepub const fn split_remainder(self, parts: i32) -> i32
pub const fn split_remainder(self, parts: i32) -> i32
Returns the quantum remainder when splitting this value into parts.
Returns zero if parts <= 0.
Source§impl Lunit
impl Lunit
Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Returns the absolute decoded value, saturating to the payload range.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn abs_meta(self) -> Self
pub const fn abs_meta(self) -> Self
Returns the absolute decoded value, preserving boundary metadata.
Inherited metadata is preserved; operation metadata is recorded if this clips.
Sourcepub const fn abs_nometa(self) -> Self
pub const fn abs_nometa(self) -> Self
Returns the absolute decoded value without metadata.
No metadata is propagated or generated.
Sourcepub const fn sat_add(self, rhs: Self) -> Self
pub const fn sat_add(self, rhs: Self) -> Self
Saturating addition.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_add_meta(self, rhs: Self) -> Self
pub const fn sat_add_meta(self, rhs: Self) -> Self
Saturating addition, preserving boundary metadata.
Inherited metadata is merged; operation metadata is recorded if this clips.
Sourcepub const fn sat_add_nometa(self, rhs: Self) -> Self
pub const fn sat_add_nometa(self, rhs: Self) -> Self
Saturating addition without metadata.
No metadata is propagated or generated.
Sourcepub const fn sat_add_floor_zero(self, rhs: Self) -> Self
pub const fn sat_add_floor_zero(self, rhs: Self) -> Self
Adds rhs,
saturating to the payload range, then applying a zero floor.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_add_floor_zero_meta(self, rhs: Self) -> Self
pub const fn sat_add_floor_zero_meta(self, rhs: Self) -> Self
Adds rhs, preserving metadata,
saturating to the payload range, then applying a zero floor.
Sourcepub const fn sat_add_ceil_zero(self, rhs: Self) -> Self
pub const fn sat_add_ceil_zero(self, rhs: Self) -> Self
Adds rhs,
saturating to the payload range, then applying a zero ceiling.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_add_ceil_zero_meta(self, rhs: Self) -> Self
pub const fn sat_add_ceil_zero_meta(self, rhs: Self) -> Self
Adds rhs, preserving metadata,
saturating to the payload range, then applying a zero ceiling.
Sourcepub const fn sat_sub(self, rhs: Self) -> Self
pub const fn sat_sub(self, rhs: Self) -> Self
Saturating subtraction.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_sub_meta(self, rhs: Self) -> Self
pub const fn sat_sub_meta(self, rhs: Self) -> Self
Saturating subtraction, preserving boundary metadata.
Inherited metadata is merged; operation metadata is recorded if this clips.
Sourcepub const fn sat_sub_nometa(self, rhs: Self) -> Self
pub const fn sat_sub_nometa(self, rhs: Self) -> Self
Saturating subtraction without metadata.
No metadata is propagated or generated.
Sourcepub const fn sat_sub_floor_zero(self, rhs: Self) -> Self
pub const fn sat_sub_floor_zero(self, rhs: Self) -> Self
Subtracts rhs,
saturating to the payload range, then applying a zero floor.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_sub_floor_zero_meta(self, rhs: Self) -> Self
pub const fn sat_sub_floor_zero_meta(self, rhs: Self) -> Self
Subtracts rhs, preserving metadata,
saturating to the payload range, then applying a zero floor.
Sourcepub const fn sat_sub_ceil_zero(self, rhs: Self) -> Self
pub const fn sat_sub_ceil_zero(self, rhs: Self) -> Self
Subtracts rhs,
saturating to the payload range, then applying a zero ceiling.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_sub_ceil_zero_meta(self, rhs: Self) -> Self
pub const fn sat_sub_ceil_zero_meta(self, rhs: Self) -> Self
Subtracts rhs, preserving metadata,
saturating to the payload range, then applying a zero ceiling.
Sourcepub const fn sat_mul(self, rhs: Self) -> Self
pub const fn sat_mul(self, rhs: Self) -> Self
Saturating multiplication.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_mul_meta(self, rhs: Self) -> Self
pub const fn sat_mul_meta(self, rhs: Self) -> Self
Saturating multiplication, preserving boundary metadata.
Inherited metadata is merged; operation metadata is recorded if this clips.
Sourcepub const fn sat_mul_nometa(self, rhs: Self) -> Self
pub const fn sat_mul_nometa(self, rhs: Self) -> Self
Saturating multiplication without metadata.
No metadata is propagated or generated.
Sourcepub const fn sat_mul_div(self, num: i32, den: i32) -> Option<Self> ⓘ
pub const fn sat_mul_div(self, num: i32, den: i32) -> Option<Self> ⓘ
Multiplies by num, divides by den, and saturates the final result.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Returns None when den == 0.
Sourcepub const fn sat_mul_div_meta(self, num: i32, den: i32) -> Option<Self> ⓘ
pub const fn sat_mul_div_meta(self, num: i32, den: i32) -> Option<Self> ⓘ
Multiplies by num, divides by den, and saturates the final result,
preserving boundary metadata.
Inherited metadata is merged; operation metadata is recorded if this clips.
Returns None when den == 0.
Sourcepub const fn sat_mul_div_nometa(self, num: i32, den: i32) -> Option<Self> ⓘ
pub const fn sat_mul_div_nometa(self, num: i32, den: i32) -> Option<Self> ⓘ
Multiplies by num, divides by den, and saturates the final result without metadata.
No metadata is propagated or generated. Returns None when den == 0.
Sourcepub const fn sat_dist(self, rhs: Self) -> Self
pub const fn sat_dist(self, rhs: Self) -> Self
Returns the absolute distance between decoded values, saturating to the payload range.
Inherited metadata is ignored; operation metadata is recorded if this clips.
Sourcepub const fn sat_dist_meta(self, rhs: Self) -> Self
pub const fn sat_dist_meta(self, rhs: Self) -> Self
Returns the absolute distance between decoded values, saturating to the payload range.
Inherited metadata is merged; operation metadata is recorded if this clips.
Sourcepub const fn sat_dist_nometa(self, rhs: Self) -> Self
pub const fn sat_dist_nometa(self, rhs: Self) -> Self
Returns the absolute distance between decoded values, saturating to the payload range.
No metadata is propagated or generated.
Source§impl Lunit
§Checked operations
impl Lunit
§Checked operations
Sourcepub const fn che_add(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_add(self, rhs: Self) -> Option<Self> ⓘ
Checked addition.
Inherited metadata is ignored.
Returns None if the exact result escapes the payload range.
Sourcepub const fn che_add_meta(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_add_meta(self, rhs: Self) -> Option<Self> ⓘ
Checked addition, preserving boundary metadata.
Inherited metadata is merged when the result fits.
Sourcepub const fn che_sub(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_sub(self, rhs: Self) -> Option<Self> ⓘ
Checked subtraction.
Inherited metadata is ignored.
Returns None if the exact result escapes the payload range.
Sourcepub const fn che_sub_meta(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_sub_meta(self, rhs: Self) -> Option<Self> ⓘ
Checked subtraction, preserving boundary metadata.
Inherited metadata is merged when the result fits.
Sourcepub const fn che_mul(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_mul(self, rhs: Self) -> Option<Self> ⓘ
Checked multiplication.
Inherited metadata is ignored.
Returns None if the exact result escapes the payload range.
Sourcepub const fn che_mul_meta(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_mul_meta(self, rhs: Self) -> Option<Self> ⓘ
Checked multiplication, preserving boundary metadata.
Inherited metadata is merged when the result fits.
Sourcepub const fn che_mul_div(self, num: i32, den: i32) -> Option<Self> ⓘ
pub const fn che_mul_div(self, num: i32, den: i32) -> Option<Self> ⓘ
Multiplies by num, divides by den, and checks the final result.
Inherited metadata is ignored.
Returns None when den == 0 or the final result escapes the payload range.
Sourcepub const fn che_mul_div_meta(self, num: i32, den: i32) -> Option<Self> ⓘ
pub const fn che_mul_div_meta(self, num: i32, den: i32) -> Option<Self> ⓘ
Multiplies by num, divides by den, and checks the final result.
Inherited metadata is merged when the result fits.
Returns None when den == 0 or the final result escapes the payload range.
Sourcepub const fn che_dist(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_dist(self, rhs: Self) -> Option<Self> ⓘ
Returns the absolute distance between the decoded values.
Returns None if the exact distance cannot be represented as a payload value.
Sourcepub const fn che_dist_meta(self, rhs: Self) -> Option<Self> ⓘ
pub const fn che_dist_meta(self, rhs: Self) -> Option<Self> ⓘ
Returns the absolute distance between the decoded values.
Inherited metadata is merged when the result fits.
Returns None if the exact distance cannot be represented as a payload value.
Source§impl Lunit
§Modular operations
impl Lunit
§Modular operations
Source§impl Lunit
§Upcasted outcome operations
impl Lunit
§Upcasted outcome operations
Sourcepub const fn add_up(self, rhs: Self) -> i64
pub const fn add_up(self, rhs: Self) -> i64
Returns the exact upcasted sum of the decoded values.
Sourcepub const fn sub_up(self, rhs: Self) -> i64
pub const fn sub_up(self, rhs: Self) -> i64
Returns the exact upcasted difference of the decoded values.
Trait Implementations§
impl Copy for Lunit
impl Eq for Lunit
Source§impl Ord for Lunit
impl Ord for Lunit
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for Lunit
impl RefUnwindSafe for Lunit
impl Send for Lunit
impl Sync for Lunit
impl Unpin for Lunit
impl UnsafeUnpin for Lunit
impl UnwindSafe for Lunit
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
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<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice only.