Skip to content

Commit e79465f

Browse files
committed
Make Measurable::measure take &mut self
1 parent b64a4ea commit e79465f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/tree/measure_func.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use crate::style::AvailableSpace;
55
#[cfg(any(feature = "std", feature = "alloc"))]
66
use crate::util::sys::Box;
77

8-
/// A function type that can be used in a [`MeasureFunc`]
8+
/// Represents a node that can be sized A function type that can be used in a [`MeasureFunc`]
99
///
10-
/// This trait is automatically implemented for all types (including closures) that define a function with the appropriate type signature.
10+
/// This trait is automatically implemented for `FnMut` closures that define a function with the appropriate type signature.
1111
pub trait Measurable {
1212
/// A user-defined context which is passed to taffy when the `compute_layout` function is called, and which Taffy then passes
1313
/// into measure functions when it calls them
1414
type Context;
1515

1616
/// Measure node
1717
fn measure(
18-
&self,
18+
&mut self,
1919
known_dimensions: Size<Option<f32>>,
2020
available_space: Size<AvailableSpace>,
2121
context: &mut Self::Context,
@@ -26,20 +26,31 @@ pub trait Measurable {
2626
pub enum MeasureFunc<Context = ()> {
2727
/// Stores an unboxed function
2828
#[allow(clippy::type_complexity)]
29-
Raw(fn(Size<Option<f32>>, Size<AvailableSpace>, context: &mut Context) -> Size<f32>),
29+
Raw(fn(Size<Option<f32>>, Size<AvailableSpace>, &mut Context) -> Size<f32>),
3030

3131
/// Stores a boxed function
3232
#[cfg(any(feature = "std", feature = "alloc"))]
3333
Boxed(Box<dyn Measurable<Context = Context>>),
3434
}
3535

36+
/// A function that can be used to compute the intrinsic size of a node
37+
pub enum SyncMeasureFunc<Context = ()> {
38+
/// Stores an unboxed function
39+
#[allow(clippy::type_complexity)]
40+
Raw(fn(Size<Option<f32>>, Size<AvailableSpace>, &mut Context) -> Size<f32>),
41+
42+
/// Stores a boxed function
43+
#[cfg(any(feature = "std", feature = "alloc"))]
44+
Boxed(Box<dyn Measurable<Context = Context> + Send + Sync>),
45+
}
46+
3647
impl<Context> Measurable for MeasureFunc<Context> {
3748
type Context = Context;
3849

3950
/// Call the measure function to measure the node
4051
#[inline(always)]
4152
fn measure(
42-
&self,
53+
&mut self,
4354
known_dimensions: Size<Option<f32>>,
4455
available_space: Size<AvailableSpace>,
4556
context: &mut Context,
@@ -52,24 +63,13 @@ impl<Context> Measurable for MeasureFunc<Context> {
5263
}
5364
}
5465

55-
/// A function that can be used to compute the intrinsic size of a node
56-
pub enum SyncMeasureFunc<Context = ()> {
57-
/// Stores an unboxed function
58-
#[allow(clippy::type_complexity)]
59-
Raw(fn(Size<Option<f32>>, Size<AvailableSpace>, context: &mut Context) -> Size<f32>),
60-
61-
/// Stores a boxed function
62-
#[cfg(any(feature = "std", feature = "alloc"))]
63-
Boxed(Box<dyn Measurable<Context = Context> + Send + Sync>),
64-
}
65-
6666
impl<Context> Measurable for SyncMeasureFunc<Context> {
6767
type Context = Context;
6868

6969
/// Call the measure function to measure the node
7070
#[inline(always)]
7171
fn measure(
72-
&self,
72+
&mut self,
7373
known_dimensions: Size<Option<f32>>,
7474
available_space: Size<AvailableSpace>,
7575
context: &mut Context,

0 commit comments

Comments
 (0)