A read only no alias reference
Rust Internals [Unofficial]
June 24, 2026
chrefr:
It is already possible to do that:
This doesn't quite work:
let a = 42u8;
let r = ExclusiveReadOnly::new(&a);
error[E0308]: mismatched types
--> src/main.rs:19:36
|
19 | let r = ExclusiveReadOnly::new(&a);
| ---------------------- ^^ types differ in mutability
| |
| arguments to this function are incorrect
let a = 42u8;
let r = ExclusiveReadOnly::new(&mut a);
error[E0596]: cannot borrow `a` as mutable, as it is not declared as mutable
--> src/main.rs:19:36
|
19 | let r = ExclusiveReadOnly::new(&mut a);
| ^^^^^^ cannot borrow as mutable
|
Discussion in the ATmosphere