# HG changeset patch # User Tuomo Valkonen # Date 1756789529 18000 # Node ID 45d03cf92c23ee5abdc78c44142e05a9b281a274 # Parent 03f34ba556854b53e2441453a091c81bfd2ce1b7 bazquk diff -r 03f34ba55685 -r 45d03cf92c23 src/direct_product.rs --- a/src/direct_product.rs Mon Sep 01 23:08:27 2025 -0500 +++ b/src/direct_product.rs Tue Sep 02 00:05:29 2025 -0500 @@ -392,6 +392,8 @@ D: Decomposition, Q: Decomposition, { + type OwnedInstance = Pair; + type Decomposition<'b> = Pair, Q::Decomposition<'b>> where @@ -441,7 +443,7 @@ } #[inline] - fn cow<'b>(self) -> MyCow<'b, Pair> + fn cow<'b>(self) -> MyCow<'b, Pair> where Self: 'b, { @@ -449,7 +451,7 @@ } #[inline] - fn own(self) -> Pair { + fn own(self) -> Pair { Pair(self.0.own(), self.1.own()) } } @@ -492,7 +494,7 @@ } #[inline] - fn cow<'b>(self) -> MyCow<'b, Pair> + fn cow<'b>(self) -> MyCow<'b, Pair> where Self: 'b, { @@ -500,7 +502,7 @@ } #[inline] - fn own(self) -> Pair { + fn own(self) -> Pair { let Pair(ref u, ref v) = self; Pair(u.own(), v.own()) } 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 diff -r 03f34ba55685 -r 45d03cf92c23 src/sets.rs --- a/src/sets.rs Mon Sep 01 23:08:27 2025 -0500 +++ b/src/sets.rs Tue Sep 02 00:05:29 2025 -0500 @@ -3,7 +3,7 @@ */ use crate::euclidean::Euclidean; -use crate::instance::{Instance, Space}; +use crate::instance::{BasicDecomposition, Instance, Space}; use crate::loc::Loc; use crate::types::*; use serde::Serialize; @@ -51,7 +51,7 @@ impl Set for $range where Idx : PartialOrd, - U : PartialOrd + Space, + U : PartialOrd + Space + Clone, Idx : PartialOrd { #[inline] @@ -85,10 +85,7 @@ { #[inline] pub fn new(orthogonal: A, offset: F) -> Self { - Halfspace { - orthogonal: orthogonal, - offset: offset, - } + Halfspace { orthogonal: orthogonal, offset: offset } } }