| 213 where |
213 where |
| 214 X: 'b, |
214 X: 'b, |
| 215 Self: 'b; |
215 Self: 'b; |
| 216 |
216 |
| 217 /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. |
217 /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. |
| 218 fn own(self) -> D::OwnedInstance; |
218 fn own(self) -> X; |
| 219 |
219 |
| 220 // ************** automatically implemented methods below from here ************** |
220 // ************** automatically implemented methods below from here ************** |
| 221 |
221 |
| 222 /// Returns an owned instance or reference to `X`, converting non-true instances when necessary. |
222 /// Returns an owned instance or reference to `X`, converting non-true instances when necessary. |
| 223 /// |
223 /// |
| 224 /// Default implementation uses [`Self::own`]. Consumes the input. |
224 /// Default implementation uses [`Self::own`]. Consumes the input. |
| 225 fn cow<'b>(self) -> MyCow<'b, D::OwnedInstance> |
225 fn cow<'b>(self) -> MyCow<'b, X> |
| 226 where |
226 where |
| 227 Self: 'b, |
227 Self: 'b, |
| 228 { |
228 { |
| 229 MyCow::Owned(self.own()) |
229 MyCow::Owned(self.own()) |
| 230 } |
230 } |
| 231 |
231 |
| 232 #[inline] |
232 #[inline] |
| 233 /// Evaluates `f` on a reference to self. |
233 /// Evaluates `f` on a reference to self. |
| 234 /// |
234 /// |
| 235 /// Default implementation uses [`Self::cow`]. Consumes the input. |
235 /// Default implementation uses [`Self::cow`]. Consumes the input. |
| 236 fn eval<'b, R>(self, f: impl FnOnce(&D::OwnedInstance) -> R) -> R |
236 fn eval<'b, R>(self, f: impl FnOnce(&X) -> R) -> R |
| 237 where |
237 where |
| 238 X: 'b, |
238 X: 'b, |
| 239 Self: 'b, |
239 Self: 'b, |
| 240 { |
240 { |
| 241 f(&*self.cow()) |
241 f(&*self.cow()) |
| 243 |
243 |
| 244 #[inline] |
244 #[inline] |
| 245 /// Evaluates `f` or `g` depending on whether a reference or owned value is available. |
245 /// Evaluates `f` or `g` depending on whether a reference or owned value is available. |
| 246 /// |
246 /// |
| 247 /// Default implementation uses [`Self::cow`]. Consumes the input. |
247 /// Default implementation uses [`Self::cow`]. Consumes the input. |
| 248 fn either<'b, R>( |
248 fn either<'b, R>(self, f: impl FnOnce(X) -> R, g: impl FnOnce(&X) -> R) -> R |
| 249 self, |
|
| 250 f: impl FnOnce(D::OwnedInstance) -> R, |
|
| 251 g: impl FnOnce(&D::OwnedInstance) -> R, |
|
| 252 ) -> R |
|
| 253 where |
249 where |
| 254 Self: 'b, |
250 Self: 'b, |
| 255 { |
251 { |
| 256 match self.cow() { |
252 match self.cow() { |
| 257 EitherDecomp::Owned(x) => f(x), |
253 EitherDecomp::Owned(x) => f(x), |