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