diff -r 03f34ba55685 -r 45d03cf92c23 src/instance.rs --- a/src/instance.rs Mon Sep 01 23:08:27 2025 -0500 +++ b/src/instance.rs Tue Sep 02 00:05:29 2025 -0500 @@ -144,6 +144,9 @@ /// Marker type for decompositions to be used with [`Instance`]. pub trait Decomposition: Sized { + /// Owned instance + type OwnedInstance: Instance; + /// Possibly owned form of the decomposition type Decomposition<'b>: Instance where @@ -156,8 +159,11 @@ where X: 'b; - /// Left the lightweight reference type into a full decomposition type. + /// Lift the lightweight reference type into a full decomposition type. fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b>; + + // /// Lift the lightweight reference type into a fully owned type + // fn full_lift<'b>(r: Self::Reference<'b>) -> Self::OwnedInstance; } /// Most common [`Decomposition`] (into `Either`) that allows working with owned @@ -165,7 +171,9 @@ #[derive(Copy, Clone, Debug)] pub struct BasicDecomposition; -impl Decomposition for BasicDecomposition { +impl Decomposition for BasicDecomposition { + type OwnedInstance = X; + type Decomposition<'b> = MyCow<'b, X> where @@ -207,14 +215,14 @@ Self: 'b; /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. - fn own(self) -> X; + fn own(self) -> D::OwnedInstance; // ************** automatically implemented methods below from here ************** /// Returns an owned instance or reference to `X`, converting non-true instances when necessary. /// /// Default implementation uses [`Self::own`]. Consumes the input. - fn cow<'b>(self) -> MyCow<'b, X> + fn cow<'b>(self) -> MyCow<'b, D::OwnedInstance> where Self: 'b, { @@ -225,7 +233,7 @@ /// Evaluates `f` on a reference to self. /// /// Default implementation uses [`Self::cow`]. Consumes the input. - fn eval<'b, R>(self, f: impl FnOnce(&X) -> R) -> R + fn eval<'b, R>(self, f: impl FnOnce(&D::OwnedInstance) -> R) -> R where X: 'b, Self: 'b, @@ -237,7 +245,11 @@ /// Evaluates `f` or `g` depending on whether a reference or owned value is available. /// /// Default implementation uses [`Self::cow`]. Consumes the input. - fn either<'b, R>(self, f: impl FnOnce(X) -> R, g: impl FnOnce(&X) -> R) -> R + fn either<'b, R>( + self, + f: impl FnOnce(D::OwnedInstance) -> R, + g: impl FnOnce(&D::OwnedInstance) -> R, + ) -> R where Self: 'b, { @@ -248,7 +260,7 @@ } } -impl Instance for X { +impl Instance for X { #[inline] fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where @@ -281,7 +293,7 @@ } } -impl<'a, X: Space> Instance for &'a X { +impl<'a, X: Space + Clone> Instance for &'a X { #[inline] fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where @@ -302,7 +314,7 @@ #[inline] fn own(self) -> X { - self.into_owned() + self.clone() } #[inline] @@ -314,7 +326,7 @@ } } -impl<'a, X: Space> Instance for &'a mut X { +impl<'a, X: Space + Clone> Instance for &'a mut X { #[inline] fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where @@ -335,7 +347,7 @@ #[inline] fn own(self) -> X { - self.into_owned() + self.clone() } #[inline] @@ -347,7 +359,7 @@ } } -impl<'a, X: Space> Instance for MyCow<'a, X> { +impl<'a, X: Space + Clone> Instance for MyCow<'a, X> { #[inline] fn eval_decompose<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where