--- a/src/instance.rs Mon May 12 20:40:14 2025 -0500 +++ b/src/instance.rs Mon May 12 21:56:42 2025 -0500 @@ -62,20 +62,10 @@ /// Marker type for decompositions to be used with [`Instance`]. pub trait Decomposition<X: Space>: Sized { - /// Possibly owned form of the decomposition + /// The composition type Decomposition<'b>: Instance<X, Self> where X: 'b; - /// Unlikely owned form of the decomposition. - /// Type for a lightweight intermediate conversion that does not own the original variable. - /// Usually this is just a reference, but may also be a lightweight structure that - /// contains references; see the implementation for [`crate::direct_product::Pair`]. - type Reference<'b>: Instance<X, Self> + Copy - where - X: 'b; - - /// Left the lightweight reference type into a full decomposition type. - fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b>; } /// Most common [`Decomposition`] (into `Either<X, &'b X>`) that allows working with owned @@ -88,15 +78,6 @@ = MyCow<'b, X> where X: 'b; - type Reference<'b> - = &'b X - where - X: 'b; - - #[inline] - fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b> { - MyCow::Borrowed(r) - } } /// Helper trait for functions to work with either owned values or references to either the @@ -117,7 +98,7 @@ /// 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_decompose<'b, R>(&'b self, f: impl FnOnce(D::Decomposition<'b>) -> R) -> R where X: 'b, Self: 'b; @@ -175,12 +156,12 @@ } #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where X: 'b, Self: 'b, { - f(self) + f(MyCow::Borrowed(&self)) } #[inline] @@ -208,12 +189,12 @@ } #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where X: 'b, Self: 'b, { - f(*self) + f(MyCow::Borrowed(self)) } #[inline] @@ -241,12 +222,12 @@ } #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where X: 'b, Self: 'b, { - f(*self) + f(EitherDecomp::Borrowed(self)) } #[inline] @@ -275,14 +256,14 @@ } #[inline] - fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R + fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(MyCow<'b, X>) -> R) -> R where X: 'b, Self: 'b, { match self { - MyCow::Borrowed(a) => f(a), - MyCow::Owned(b) => f(&b), + MyCow::Borrowed(a) => f(MyCow::Borrowed(a)), + MyCow::Owned(b) => f(MyCow::Borrowed(&b)), } }