trait
BorrowMut
Expose a mutable borrowed representation of an owned value. This complements Borrow; use AsMut instead when only a reference conversion is intended. Expected stdout (not executed): [0, 0] Common mistake: Assuming the trait creates a new owned value.
Formal Syntax & Structure
rust syntaxrust
T: BorrowMut<[E]>Working Example
Example Snippetrust
fn main() { use std::borrow::BorrowMut; fn reset<T: BorrowMut<[i32]>>(data: &mut T) { data.borrow_mut().fill(0); } let mut data = vec![4, 9]; reset(&mut data); println!("{data:?}");}