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
use Borrow;
/// `Borrowable` means it can be either T or &T.
///
/// Using this over [Borrow], allow accepting T or &T
/// as argument with type-deduction:
/// ```
/// # use hibit_tree::utils::Borrowable;
/// # use std::fmt::Debug;
/// #[derive(Debug)]
/// struct S;
/// impl Borrowable for S {type Borrowed = S;}
///
/// fn test(v: impl Borrowable<Borrowed: Debug>){
/// println!("{:?}", v.borrow());
/// }
///
/// fn main(){
/// test(S);
/// test(&S);
/// }
/// ```
/// While [Borrow] will fail to compile for this case:
///
/// ```compile_fail
/// # use std::borrow::Borrow;
/// # use std::fmt::Debug;
/// #[derive(Debug)]
/// struct S;
///
/// fn test<S: Debug>(v: impl Borrow<S>){
/// println!("{:?}", v.borrow());
/// }
///
/// fn main(){
/// test(S);
/// test(&S); // error: type annotations needed.
/// // cannot infer type for type parameter `S` declared on the function `test`
/// }
/// ```
// Not necessary?
/*pub trait BorrowableMut: Borrowable + BorrowMut<Self::Borrowed>{}*/