1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// The borrowed return type of a `#[memoize(as_ref)]` function.
///
/// `#[memoize]` stores the function's return value in the request cache and
/// hands out `&T`. With `as_ref`, the macro instead borrows the cached
/// value's contents through this trait, so an `Option<T>` or `Result<T, E>`
/// return value comes back as `Option<&T>` or `Result<&T, &E>`.
///
/// Implement this trait for your own return type to use it with
/// `#[memoize(as_ref)]`:
///
/// ```rust
/// use topcoat::context::MemoizeAsRef;
///
/// /// A custom optional value.
/// enum Maybe<T> {
/// Some(T),
/// None,
/// }
///
/// impl<T> MemoizeAsRef for Maybe<T> {
/// type AsRef<'a>
/// = Maybe<&'a T>
/// where
/// Self: 'a;
///
/// fn as_ref(&self) -> Self::AsRef<'_> {
/// match self {
/// Maybe::Some(value) => Maybe::Some(value),
/// Maybe::None => Maybe::None,
/// }
/// }
/// }
/// ```