How do I empty a slice in a RefMut<&mut [u8]>?

Solution 1:

You can use the dereference operator to write back to the RefCell.

let refcell: RefCell<&[u8]> = RefCell::new(&[1, 2, 3]);
{
    let mut data = refcell.borrow_mut();
    *data = &[];
    // or equivalently, *refcell.borrow_mut() = &[];
}
println!("{:?}", refcell); // RefCell { value: [] }