| 6 pub enum EitherDecomp<A, B> { |
6 pub enum EitherDecomp<A, B> { |
| 7 Owned(A), |
7 Owned(A), |
| 8 Borrowed(B), |
8 Borrowed(B), |
| 9 } |
9 } |
| 10 |
10 |
| 11 /// A very basic implementation of [`Cow`] without a [`Clone`] trait dependency. |
11 /// A very basic implementation of [`std::borrow::Cow`] without a [`Clone`] trait dependency. |
| 12 pub type MyCow<'b, X> = EitherDecomp<X, &'b X>; |
12 pub type MyCow<'b, X> = EitherDecomp<X, &'b X>; |
| 13 |
13 |
| 14 impl<'b, X> std::ops::Deref for MyCow<'b, X> { |
14 impl<'b, X> std::ops::Deref for MyCow<'b, X> { |
| 15 type Target = X; |
15 type Target = X; |
| 16 |
16 |
| 87 } |
87 } |
| 88 |
88 |
| 89 /// Helper trait for functions to work with either owned values or references to either the |
89 /// Helper trait for functions to work with either owned values or references to either the |
| 90 /// “principal type” `X` or types some present a subset of `X`. In the latter sense, this |
90 /// “principal type” `X` or types some present a subset of `X`. In the latter sense, this |
| 91 /// generalises [`std::borrow::ToOwned`], [`std::borrow::Borrow`], and [`std::borrow::Cow`]. |
91 /// generalises [`std::borrow::ToOwned`], [`std::borrow::Borrow`], and [`std::borrow::Cow`]. |
| 92 /// This type also includes iteratation facilities when `X` is a [`Collection`], to avoid |
|
| 93 /// the possibly costly conversion of such subset types into `X`. |
|
| 94 pub trait Instance<X : Space, D = <X as Space>::Decomp> : Sized where D : Decomposition<X> { |
92 pub trait Instance<X : Space, D = <X as Space>::Decomp> : Sized where D : Decomposition<X> { |
| 95 /// Decomposes self according to `decomposer`. |
93 /// Decomposes self according to `decomposer`. |
| 96 fn decompose<'b>(self) -> D::Decomposition<'b> |
94 fn decompose<'b>(self) -> D::Decomposition<'b> |
| 97 where Self : 'b, X : 'b; |
95 where Self : 'b, X : 'b; |
| 98 |
96 |