Function show_notes::e019::demonstrate_mut_cow

source ·
pub fn demonstrate_mut_cow(_point: &mut BJustClonePoint)
Expand description

What if we need a mutable reference to the wrapped type?

§Examples

We can get a mutable reference to the wrapped item, even if the wrapped item isn’t itself mutable, as long as it’s Clone-able. In this case, we’re making a copy—this is explicit in the to_mut() call. If the underlying item isn’t mutably accessible, we’ll just get a mutable copy.

let mut a_point: Cow<BJustClonePoint> = Cow::Owned(BJustClonePoint::origin());
demonstrate_mut_cow(a_point.to_mut());