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
pub trait Ref<'a, T> {
fn convert(val: &'a T) -> Self;
}
impl<'a, T> Ref<'a, T> for &'a T {
fn convert(val: &'a T) -> &'a T {
val
}
}
impl<'a, T: Copy> Ref<'a, T> for T {
fn convert(val: &'a T) -> T {
*val
}
}
impl<'a, K, V> Ref<'a, (K, V)> for (&'a K, &'a V) {
fn convert(val: &'a (K, V)) -> (&'a K, &'a V) {
let (ref k, ref v) = *val;
(k, v)
}
}
impl<'a, K: Copy, V> Ref<'a, (K, V)> for (K, &'a V) {
fn convert(val: &'a (K, V)) -> (K, &'a V) {
let (k, ref v) = *val;
(k, v)
}
}
pub trait RefMut<'a, T> {
fn convert(val: &'a mut T) -> Self;
}
impl<'a, T> RefMut<'a, T> for &'a mut T {
fn convert(val: &'a mut T) -> &'a mut T {
val
}
}
impl<'a, K, V> RefMut<'a, (K, V)> for (&'a K, &'a mut V) {
fn convert(val: &'a mut (K, V)) -> (&'a K, &'a mut V) {
let (ref key, ref mut val) = *val;
(key, val)
}
}
impl<'a, K: Copy, V> RefMut<'a, (K, V)> for (K, &'a mut V) {
fn convert(val: &'a mut (K, V)) -> (K, &'a mut V) {
(val.0, &mut val.1)
}
}