| Crates.io | mutify |
| lib.rs | mutify |
| version | 0.1.0 |
| created_at | 2024-01-11 06:19:20.926805+00 |
| updated_at | 2024-01-11 06:19:20.926805+00 |
| description | Macro for coercing a `mut var: T` or `var: &mut T` into a `&mut T`. |
| homepage | |
| repository | https://github.com/mintlu8/mutify |
| max_upload_size | |
| id | 1095921 |
| size | 16,464 |
Macro for coercing a mut var: T or var: &mut T into a &mut T.
A naive apporach would be putting a &mut before the expression,
however this doesn't work.
let func = |v: &mut i32| *v += 1;
let mut b = 0;
let a = &mut b;
// `a` is not mutable.
func(&mut a);
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);
A magic function called __coerce_mut is used here, don't name your
functions that and you are good!