Ask a value a question through a reference

A method taking `self` can only be called on a value, so anywhere the caller
holds a reference it has to dereference to ask -- which costs the caller
whether or not the type is `Copy` (Bryan, 2026-09-20, correcting the opposite
change made in 7502176).

So every method that answers a question about a value takes `&self`:
`Holds`'s four, `AxisHolds` and `LayoutHolds`'s three each, `LayoutLen`'s
`is_px`, `is_only_leftover`, `declared` and `fills`, and `Size::within_box`.
The two callers passing `LayoutLen::declared` as a function value say the
closure instead.

Builders that return a changed copy, and methods on a handle that is meant to
be given up, still take `self`.
This commit is contained in:
iris-ai committed 2026-09-20 01:30:29 -04:00
1 parent 750217631d
commit 445287c95c
6 files changed
+17 -17

No files matched your search

+3 -3
View File
@@ -148,20 +148,20 @@ impl LayoutLen {
/// Only pixels: the same number of them whatever box it lands in, and /// Only pixels: the same number of them whatever box it lands in, and
/// whatever anyone else in the row asks for. A length that is any part /// whatever anyone else in the row asks for. A length that is any part
/// of a box or of what is left over is not one. /// of a box or of what is left over is not one.
pub fn is_px(self) -> bool { pub fn is_px(&self) -> bool {
self.rel == Rel::ZERO && self.leftover == Weight::ZERO self.rel == Rel::ZERO && self.leftover == Weight::ZERO
} }
/// Nothing but a claim on what is left over, so there is no length here /// Nothing but a claim on what is left over, so there is no length here
/// at all where nothing is. /// at all where nothing is.
pub fn is_only_leftover(self) -> bool { pub fn is_only_leftover(&self) -> bool {
self.leftover > Weight::ZERO && self.without_leftover() == Len::ZERO self.leftover > Weight::ZERO && self.without_leftover() == Len::ZERO
} }
/// This as a length of a box, where it is one. `leftover` is not: a /// This as a length of a box, where it is one. `leftover` is not: a
/// share of what is left over is a length only to whoever divides one, /// share of what is left over is a length only to whoever divides one,
/// so it passes up in the reported size instead and is resolved there. /// so it passes up in the reported size instead and is resolved there.
pub fn declared(self) -> Option<Len> { pub fn declared(&self) -> Option<Len> {
(self.leftover == Weight::ZERO).then(|| self.without_leftover()) (self.leftover == Weight::ZERO).then(|| self.without_leftover())
} }
+4 -4
View File
@@ -29,17 +29,17 @@ impl Holds {
Self { lo: len, hi: len } Self { lo: len, hi: len }
} }
pub const fn contains(self, len: Px) -> bool { pub const fn contains(&self, len: Px) -> bool {
len.raw() >= self.lo.raw() && len.raw() <= self.hi.raw() len.raw() >= self.lo.raw() && len.raw() <= self.hi.raw()
} }
/// Every length `other` holds for is one this holds for, so a drawing /// Every length `other` holds for is one this holds for, so a drawing
/// made under this range is still good wherever `other` is. /// made under this range is still good wherever `other` is.
pub const fn covers(self, other: Self) -> bool { pub const fn covers(&self, other: Self) -> bool {
self.lo.raw() <= other.lo.raw() && self.hi.raw() >= other.hi.raw() self.lo.raw() <= other.lo.raw() && self.hi.raw() >= other.hi.raw()
} }
pub const fn and(self, other: Self) -> Self { pub const fn and(&self, other: Self) -> Self {
Self { Self {
lo: self.lo.max(other.lo), lo: self.lo.max(other.lo),
hi: self.hi.min(other.hi), hi: self.hi.min(other.hi),
@@ -57,7 +57,7 @@ impl Holds {
/// boxes therefore give one length. That is a floor rather than an /// boxes therefore give one length. That is a floor rather than an
/// allowance: inverting it is two divisions and nothing else, and the /// allowance: inverting it is two divisions and nothing else, and the
/// whole of a box maps back to itself. /// whole of a box maps back to itself.
pub const fn through(self, len: Len) -> Self { pub const fn through(&self, len: Len) -> Self {
if self.lo.raw() == Px::MIN.raw() && self.hi.raw() == Px::MAX.raw() { if self.lo.raw() == Px::MIN.raw() && self.hi.raw() == Px::MAX.raw() {
return Self::ANY; return Self::ANY;
} }
+6 -6
View File
@@ -34,7 +34,7 @@ impl AxisHolds {
region_len: None, region_len: None,
}; };
pub fn and(self, other: Self) -> Self { pub fn and(&self, other: Self) -> Self {
// Two pins of the same length disagreeing would mean one drawing was // Two pins of the same length disagreeing would mean one drawing was
// a fraction of two different lengths at once. // a fraction of two different lengths at once.
debug_assert!( debug_assert!(
@@ -53,7 +53,7 @@ impl AxisHolds {
} }
} }
pub fn covers(self, other: Self) -> bool { pub fn covers(&self, other: Self) -> bool {
self.window.covers(other.window) self.window.covers(other.window)
&& self.region.covers(other.region) && self.region.covers(other.region)
&& self && self
@@ -64,7 +64,7 @@ impl AxisHolds {
/// Whether a widget in a box `len` long, with that rel base, in that /// Whether a widget in a box `len` long, with that rel base, in that
/// window, is one this drawing holds for. /// window, is one this drawing holds for.
pub fn contains(self, window: Px, rel_base: Len, len: Len) -> bool { pub fn contains(&self, window: Px, rel_base: Len, len: Len) -> bool {
self.window.contains(window) self.window.contains(window)
&& self.rel_base.is_none_or(|pinned| pinned == rel_base) && self.rel_base.is_none_or(|pinned| pinned == rel_base)
&& self.region.contains(len.to_px(window)) && self.region.contains(len.to_px(window))
@@ -87,18 +87,18 @@ impl LayoutHolds {
y: AxisHolds::ANY, y: AxisHolds::ANY,
}; };
pub fn and(self, other: Self) -> Self { pub fn and(&self, other: Self) -> Self {
Self { Self {
x: self.x.and(other.x), x: self.x.and(other.x),
y: self.y.and(other.y), y: self.y.and(other.y),
} }
} }
pub fn covers(self, other: Self) -> bool { pub fn covers(&self, other: Self) -> bool {
self.x.covers(other.x) && self.y.covers(other.y) self.x.covers(other.x) && self.y.covers(other.y)
} }
pub fn contains(self, window: PxVec2, rel_base: UiVec2, region: UiRegion) -> bool { pub fn contains(&self, window: PxVec2, rel_base: UiVec2, region: UiRegion) -> bool {
Axis::BOTH Axis::BOTH
.into_iter() .into_iter()
.all(|axis| self[axis].contains(window[axis], rel_base[axis], region[axis].len())) .all(|axis| self[axis].contains(window[axis], rel_base[axis], region[axis].len()))
+2 -2
View File
@@ -665,7 +665,7 @@ impl Widgets {
// the box it was offered. // the box it was offered.
widget widget
.and_then(|widget| widget.size_hint(axis)) .and_then(|widget| widget.size_hint(axis))
.and_then(LayoutLen::declared) .and_then(|len| len.declared())
}) })
}) })
} }
@@ -679,7 +679,7 @@ impl LayoutLen {
/// the rule already gave the region its length, and the rule's length is /// the rule already gave the region its length, and the rule's length is
/// what the widget reports there. And an axis the parent decided from /// what the widget reports there. And an axis the parent decided from
/// the answer is the answer already. /// the answer is the answer already.
pub(super) fn fills(self, declared: Option<Len>, decided: bool) -> bool { pub(super) fn fills(&self, declared: Option<Len>, decided: bool) -> bool {
self.leftover != Weight::ZERO || declared.is_some() || decided self.leftover != Weight::ZERO || declared.is_some() || decided
} }
} }
+1 -1
View File
@@ -1167,7 +1167,7 @@ impl Size {
/// in. Both are lengths of the window, so the comparison is in its /// in. Both are lengths of the window, so the comparison is in its
/// pixels. A share is a length only to whoever divides one, so it is not /// pixels. A share is a length only to whoever divides one, so it is not
/// a claim about this box and cannot exceed it. /// a claim about this box and cannot exceed it.
fn within_box(self, region: UiRegion, window: PxVec2, axis: Axis) -> bool { fn within_box(&self, region: UiRegion, window: PxVec2, axis: Axis) -> bool {
let len = self[axis]; let len = self[axis];
let window = window[axis]; let window = window[axis];
len.leftover != Weight::ZERO len.leftover != Weight::ZERO
+1 -1
View File
@@ -22,7 +22,7 @@ impl SizeRule {
/// The length this rule gives without the widget being drawn, if it can /// The length this rule gives without the widget being drawn, if it can
/// give one. /// give one.
pub fn declared(&self) -> Option<Len> { pub fn declared(&self) -> Option<Len> {
self.exact().and_then(LayoutLen::declared) self.exact().and_then(|len| len.declared())
} }
/// The length this rule gives outright, whatever the widget reports -- /// The length this rule gives outright, whatever the widget reports --