src/instance.rs

branch
dev
changeset 173
102421d462d1
parent 171
fa8df5a14486
equal deleted inserted replaced
172:73608862ef54 173:102421d462d1
342 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(D::Reference<'b>) -> R) -> R 342 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(D::Reference<'b>) -> R) -> R
343 where 343 where
344 X: 'b, 344 X: 'b,
345 Self: 'b; 345 Self: 'b;
346 346
347 #[inline]
348 /// Evaluates `f` or `g` depending on whether a reference or owned value is available.
349 fn either<'b, R>(
350 self,
351 f: impl FnOnce(D::Decomposition<'b>) -> R,
352 _g: impl FnOnce(D::Reference<'b>) -> R,
353 ) -> R
354 where
355 X: 'b,
356 Self: 'b,
357 {
358 self.eval_decompose(f)
359 }
360
361 /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. 347 /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary.
362 fn own(self) -> X::Principal; 348 fn own(self) -> X::Principal;
363 349
364 fn decompose<'b>(self) -> D::Decomposition<'b> 350 fn decompose<'b>(self) -> D::Decomposition<'b>
365 where 351 where
385 } 371 }
386 } 372 }
387 373
388 impl<X: Space> Instance<X, BasicDecomposition> for X { 374 impl<X: Space> Instance<X, BasicDecomposition> for X {
389 #[inline] 375 #[inline]
390 fn either<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R, _g: impl FnOnce(&'b X) -> R) -> R
391 where
392 Self: 'b,
393 {
394 f(MyCow::Owned(self))
395 }
396
397 #[inline]
398 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R 376 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R
399 where 377 where
400 X: 'b, 378 X: 'b,
401 Self: 'b, 379 Self: 'b,
402 { 380 {
425 } 403 }
426 } 404 }
427 405
428 impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a X { 406 impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a X {
429 #[inline] 407 #[inline]
430 fn either<'b, R>(self, _f: impl FnOnce(MyCow<'b, X>) -> R, g: impl FnOnce(&'b X) -> R) -> R
431 where
432 Self: 'b,
433 {
434 g(self)
435 }
436
437 #[inline]
438 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R 408 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R
439 where 409 where
440 X: 'b, 410 X: 'b,
441 Self: 'b, 411 Self: 'b,
442 { 412 {
465 } 435 }
466 } 436 }
467 437
468 impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a mut X { 438 impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a mut X {
469 #[inline] 439 #[inline]
470 fn either<'b, R>(self, _f: impl FnOnce(MyCow<'b, X>) -> R, g: impl FnOnce(&'b X) -> R) -> R
471 where
472 Self: 'b,
473 {
474 g(self)
475 }
476
477 #[inline]
478 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R 440 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R
479 where 441 where
480 X: 'b, 442 X: 'b,
481 Self: 'b, 443 Self: 'b,
482 { 444 {
504 MyCow::Borrowed(self) 466 MyCow::Borrowed(self)
505 } 467 }
506 } 468 }
507 469
508 impl<'a, X: Space> Instance<X, BasicDecomposition> for MyCow<'a, X> { 470 impl<'a, X: Space> Instance<X, BasicDecomposition> for MyCow<'a, X> {
509 #[inline]
510 fn either<'b, R>(self, f: impl FnOnce(MyCow<'b, X>) -> R, _g: impl FnOnce(&'b X) -> R) -> R
511 where
512 Self: 'b,
513 {
514 f(self)
515 }
516
517 #[inline] 471 #[inline]
518 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R 472 fn eval_ref<'b, R>(&'b self, f: impl FnOnce(&'b X) -> R) -> R
519 where 473 where
520 X: 'b, 474 X: 'b,
521 Self: 'b, 475 Self: 'b,

mercurial