const REFCELL_REFMUT_INTO_MUT: ();
Expand description
ⓘ
use core::cell::{RefCell, RefMut};
let refcell = RefCell::new([0u8, 1, 2, 3]);
let core_ref_mut = refcell.borrow_mut();
let core_ref_mut = RefMut::map(core_ref_mut, |bytes| &mut bytes[..]);
// `zc_ref` now stores `core_ref_mut` internally.
let zc_ref = zerocopy::Ref::<_, u32>::new(core_ref_mut).unwrap();
// This causes `core_ref_mut` to get dropped and synthesizes a Rust
// reference to the memory `core_ref` was pointing at.
let rust_ref_mut = zc_ref.into_mut();
// UB!!! This mutates `rust_ref_mut`'s referent while it's alive.
*refcell.borrow_mut() = [0, 0, 0, 0];
println!("{}", rust_ref_mut);