Expand description
§Mutable Access Proxy
This module defines MutProxy
, a temporary proxy object that enables
ergonomic, index-like mutable access to elements within a FixedVec
.
Because FixedVec
stores its elements in a compressed, bit-packed format,
it is not possible to return a direct mutable reference (&mut T
) to an
element. Instead, methods like at_mut
return a
MutProxy
. This proxy holds a temporary, decoded copy of an element’s value.
When the proxy is dropped (goes out of scope), its Drop
implementation
automatically writes the (potentially modified) value back into the vector.
§Examples
use compressed_intvec::fixed::{FixedVec, UFixedVec, BitWidth};
let data: &[u32] = &[10, 20, 30];
let mut vec: UFixedVec<u32> = FixedVec::builder().bit_width(BitWidth::Explicit(7)).build(data).unwrap();
// Get a mutable proxy for the element at index 1.
if let Some(mut proxy) = vec.at_mut(1) {
// DerefMut allows us to modify the value.
*proxy = 99;
} // The proxy is dropped here, and the new value is written back.
assert_eq!(vec.get(1), Some(99));