| 60 i8 i16 i32 i64 i128 isize |
60 i8 i16 i32 i64 i128 isize |
| 61 f32 f64); |
61 f32 f64); |
| 62 |
62 |
| 63 /// Marker type for decompositions to be used with [`Instance`]. |
63 /// Marker type for decompositions to be used with [`Instance`]. |
| 64 pub trait Decomposition<X: Space>: Sized { |
64 pub trait Decomposition<X: Space>: Sized { |
| 65 /// Possibly owned form of the decomposition |
65 /// The composition |
| 66 type Decomposition<'b>: Instance<X, Self> |
66 type Decomposition<'b>: Instance<X, Self> |
| 67 where |
67 where |
| 68 X: 'b; |
68 X: 'b; |
| 69 /// Unlikely owned form of the decomposition. |
|
| 70 /// Type for a lightweight intermediate conversion that does not own the original variable. |
|
| 71 /// Usually this is just a reference, but may also be a lightweight structure that |
|
| 72 /// contains references; see the implementation for [`crate::direct_product::Pair`]. |
|
| 73 type Reference<'b>: Instance<X, Self> + Copy |
|
| 74 where |
|
| 75 X: 'b; |
|
| 76 |
|
| 77 /// Left the lightweight reference type into a full decomposition type. |
|
| 78 fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b>; |
|
| 79 } |
69 } |
| 80 |
70 |
| 81 /// Most common [`Decomposition`] (into `Either<X, &'b X>`) that allows working with owned |
71 /// Most common [`Decomposition`] (into `Either<X, &'b X>`) that allows working with owned |
| 82 /// values and all sorts of references. |
72 /// values and all sorts of references. |
| 83 #[derive(Copy, Clone, Debug)] |
73 #[derive(Copy, Clone, Debug)] |
| 86 impl<X: Space + Clone> Decomposition<X> for BasicDecomposition { |
76 impl<X: Space + Clone> Decomposition<X> for BasicDecomposition { |
| 87 type Decomposition<'b> |
77 type Decomposition<'b> |
| 88 = MyCow<'b, X> |
78 = MyCow<'b, X> |
| 89 where |
79 where |
| 90 X: 'b; |
80 X: 'b; |
| 91 type Reference<'b> |
|
| 92 = &'b X |
|
| 93 where |
|
| 94 X: 'b; |
|
| 95 |
|
| 96 #[inline] |
|
| 97 fn lift<'b>(r: Self::Reference<'b>) -> Self::Decomposition<'b> { |
|
| 98 MyCow::Borrowed(r) |
|
| 99 } |
|
| 100 } |
81 } |
| 101 |
82 |
| 102 /// Helper trait for functions to work with either owned values or references to either the |
83 /// Helper trait for functions to work with either owned values or references to either the |
| 103 /// “principal type” `X` or types some present a subset of `X`. In the latter sense, this |
84 /// “principal type” `X` or types some present a subset of `X`. In the latter sense, this |
| 104 /// generalises [`std::borrow::ToOwned`], [`std::borrow::Borrow`], and [`std::borrow::Cow`]. |
85 /// generalises [`std::borrow::ToOwned`], [`std::borrow::Borrow`], and [`std::borrow::Cow`]. |
| 115 X: 'b, |
96 X: 'b, |
| 116 Self: 'b; |
97 Self: 'b; |
| 117 |
98 |
| 118 /// Does a light decomposition of self `decomposer`, and evaluates `f` on the result. |
99 /// Does a light decomposition of self `decomposer`, and evaluates `f` on the result. |
| 119 /// Does not consume self. |
100 /// Does not consume self. |
| 120 fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(D::Reference<'b>) -> R) -> R |
101 fn eval_ref_decompose<'b, R>(&'b self, f: impl FnOnce(D::Decomposition<'b>) -> R) -> R |
| 121 where |
102 where |
| 122 X: 'b, |
103 X: 'b, |
| 123 Self: 'b; |
104 Self: 'b; |
| 124 |
105 |
| 125 /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. |
106 /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. |