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
65
66
67
68
69
70
71
72
73
74
//! Macro for coercing a `mut var: T` or `var: &mut T` into a `&mut T`.
//!
//! # Why
//!
//! A naive apporach would be putting a `&mut` before the expression,
//! however this doesn't work.
//!
//! ```compile_fail
//! let func = |v: &mut i32| *v += 1;
//! let mut b = 0;
//! let a = &mut b;
//! // `a` is not mutable.
//! func(&mut a);
//! ```
//!
//! # Example
//!
//! ```
//! # use mutify::mutify;
//! fn plus_one(n: &mut i32) {
//! *n += 1;
//! }
//!
//! let mut a = 3;
//! plus_one(mutify!(a));
//! assert_eq!(a, 4);
//!
//! let b = &mut a;
//! plus_one(mutify!(b));
//! assert_eq!(a, 5);
//! ```
//!
//! # Note
//!
//! A magic function called `__coerce_mut` is used here, don't name your
//! functions that and you are good!
/// Trait for coercing a `mut var: T` or `var: &mut T` into a `&mut T`.
/// Coerce a `mut var: T` or `var: &mut T` into a `&mut T`.
///
/// # Example
///
/// ```
/// # use mutify::mutify;
/// fn plus_one(n: &mut i32) {
/// *n += 1;
/// }
///
/// let mut a = 3;
/// plus_one(mutify!(a));
/// assert_eq!(a, 4);
///
/// let b = &mut a;
/// plus_one(mutify!(b));
/// assert_eq!(a, 5);
/// ```
///