diff -r 221728aeeb7e -r fa8df5a14486 src/instance.rs --- a/src/instance.rs Wed Sep 03 19:55:05 2025 -0500 +++ b/src/instance.rs Wed Sep 03 20:19:41 2025 -0500 @@ -328,14 +328,18 @@ { /// Decomposes self according to `decomposer`, and evaluate `f` on the result. /// Consumes self. + #[inline] fn eval_decompose<'b, R>(self, f: impl FnOnce(D::Decomposition<'b>) -> R) -> R where X: 'b, - Self: 'b; + Self: 'b, + { + f(self.decompose()) + } /// Does a light decomposition of self `decomposer`, and evaluates `f` on the result. /// Does not consume self. - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(D::Reference<'b>) -> R) -> R + fn eval_ref<'b, R>(&'b self, f: impl FnOnce(D::Reference<'b>) -> R) -> R where X: 'b, Self: 'b; @@ -345,7 +349,7 @@ fn either<'b, R>( self, f: impl FnOnce(D::Decomposition<'b>) -> R, - g: impl FnOnce(D::Reference<'b>) -> R, + _g: impl FnOnce(D::Reference<'b>) -> R, ) -> R where X: 'b, @@ -357,6 +361,10 @@ /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. fn own(self) -> X::Principal; + fn decompose<'b>(self) -> D::Decomposition<'b> + where + Self: 'b; + /// Returns an owned instance or reference to `X`, converting non-true instances when necessary. /// /// Default implementation uses [`Self::own`]. Consumes the input. @@ -387,16 +395,7 @@ } #[inline] - fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R - where - X: 'b, - Self: 'b, - { - f(MyCow::Owned(self)) - } - - #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R where X: 'b, Self: 'b, @@ -416,6 +415,14 @@ { self.cow_owned() } + + #[inline] + fn decompose<'b>(self) -> MyCow<'b, X> + where + Self: 'b, + { + MyCow::Owned(self) + } } impl<'a, X: Space> Instance for &'a X { @@ -428,16 +435,7 @@ } #[inline] - fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R - where - X: 'b, - Self: 'b, - { - f(MyCow::Borrowed(self)) - } - - #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R where X: 'b, Self: 'b, @@ -457,6 +455,14 @@ { self.cow_owned() } + + #[inline] + fn decompose<'b>(self) -> MyCow<'b, X> + where + Self: 'b, + { + MyCow::Borrowed(self) + } } impl<'a, X: Space> Instance for &'a mut X { @@ -469,16 +475,7 @@ } #[inline] - fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R - where - X: 'b, - Self: 'b, - { - f(EitherDecomp::Borrowed(self)) - } - - #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R where X: 'b, Self: 'b, @@ -498,6 +495,14 @@ { self.cow_owned() } + + #[inline] + fn decompose<'b>(self) -> MyCow<'b, X> + where + Self: 'b, + { + MyCow::Borrowed(self) + } } impl<'a, X: Space> Instance for MyCow<'a, X> { @@ -510,16 +515,7 @@ } #[inline] - fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R - where - X: 'b, - Self: 'b, - { - f(self) - } - - #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R where X: 'b, Self: 'b, @@ -542,6 +538,14 @@ { self.cow_owned() } + + #[inline] + fn decompose<'b>(self) -> MyCow<'b, X> + where + Self: 'b, + { + self + } } /// Marker type for mutable decompositions to be used with [`InstanceMut`].