Mon, 12 May 2025 21:56:42 -0500
instance-lifetime-fubar2
--- a/src/direct_product.rs Mon May 12 20:40:14 2025 -0500 +++ b/src/direct_product.rs Mon May 12 21:56:42 2025 -0500 @@ -365,15 +365,6 @@ = Pair<D::Decomposition<'b>, Q::Decomposition<'b>> where Pair<A, B>: 'b; - type Reference<'b> - = Pair<D::Reference<'b>, Q::Reference<'b>> - where - Pair<A, B>: 'b; - - #[inline] - fn lift<'b>(Pair(u, v): Self::Reference<'b>) -> Self::Decomposition<'b> { - Pair(D::lift(u), Q::lift(v)) - } } impl<A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V> @@ -399,7 +390,7 @@ fn eval_ref_decompose<'b, R>( &'b self, - f: impl FnOnce(Pair<D::Reference<'b>, Q::Reference<'b>>) -> R, + f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, ) -> R where Pair<A, B>: 'b, @@ -442,15 +433,13 @@ Pair<A, B>: 'b, Self: 'b, { - self.0.eval_ref_decompose(|a| { - self.1 - .eval_ref_decompose(|b| f(Pair(D::lift(a), Q::lift(b)))) - }) + self.0 + .eval_ref_decompose(|a| self.1.eval_ref_decompose(|b| f(Pair(a, b)))) } fn eval_ref_decompose<'b, R>( &'b self, - f: impl FnOnce(Pair<D::Reference<'b>, Q::Reference<'b>>) -> R, + f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, ) -> R where Pair<A, B>: 'b,
--- a/src/fe_model/p2_local_model.rs Mon May 12 20:40:14 2025 -0500 +++ b/src/fe_model/p2_local_model.rs Mon May 12 21:56:42 2025 -0500 @@ -32,7 +32,7 @@ impl<'a, F: Float> Set<Loc<1, F>> for RealInterval<F> { #[inline] fn contains<I: Instance<Loc<1, F>>>(&self, z: I) -> bool { - z.eval_ref_decompose(|&Loc([x])| { + z.eval(|&Loc([x])| { let &[Loc([x0]), Loc([x1])] = &self.0; (x0 < x && x < x1) || (x1 < x && x < x0) })
--- 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)), } }
--- a/src/nalgebra_support.rs Mon May 12 20:40:14 2025 -0500 +++ b/src/nalgebra_support.rs Mon May 12 21:56:42 2025 -0500 @@ -224,7 +224,7 @@ { #[inline] fn dot<I: Instance<Self>>(&self, other: I) -> E { - other.eval_ref_decompose(|r| Vector::<E, M, S>::dot(self, r)) + other.eval(|r| Vector::<E, M, S>::dot(self, r)) } #[inline] @@ -234,7 +234,7 @@ #[inline] fn dist2_squared<I: Instance<Self>>(&self, other: I) -> E { - other.eval_ref_decompose(|r| metric_distance_squared(self, r)) + other.eval(|r| metric_distance_squared(self, r)) } } @@ -305,7 +305,7 @@ { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> E { - other.eval_ref_decompose(|r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) + other.eval(|r| nalgebra::Norm::metric_distance(&LpNorm(1), self, r)) } } @@ -331,7 +331,7 @@ { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: L2) -> E { - other.eval_ref_decompose(|r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) + other.eval(|r| nalgebra::Norm::metric_distance(&LpNorm(2), self, r)) } } @@ -357,7 +357,7 @@ { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> E { - other.eval_ref_decompose(|r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) + other.eval(|r| nalgebra::Norm::metric_distance(&UniformNorm, self, r)) } }