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
/// `unmut!` drops a value's `mut`. It let's you mark a point in the flow when
/// an identifier mustn't be mutable anymore.
/// See [`drop`](https://doc.rust-lang.org/std/mem/fn.drop.html) to actually drop the value.
///
/// See also [`mute!`]
///
/// ```rust
/// use unmut::unmut;
///
/// let mut x = 42;
/// x *= 2;
/// unmut!(x);
/// // ...
/// ```
/// See `x` is now immutable:
/// ```rust,compile_fail
/// // ...
///# use unmut::unmut;
///# let mut x = 42;
///# x *= 2;
///# unmut!(x);
/// x *= 2;
/// // This fails to compile with:
///# let _ = r#"
/// error[E0384]: cannot assign twice to immutable variable `x`
/// --> src/lib.rs:23:1
/// |
/// 8 | unmut!(x);
/// | ---------
/// | |
/// | first assignment to `x`
/// | help: consider making this binding mutable: `mut x`
/// 9 | x *= 2;
/// | ^^^^^^ cannot assign twice to immutable variable
///
///# "#;
/// ```
/// `mute!` drops a value's `mut`.
///
/// See also [`unmut!`]
///
/// Note however that this compiles:
/// ```rust
/// use unmut::mute;
///
/// let x = 42; // not mut
/// mute!(x); // no complaints
/// ```