pub unsafe trait GetManyMutExt {
type Element;
// Required methods
fn get_many_mut<const N: usize>(
&mut self,
indices: [usize; N],
) -> Result<[&mut Self::Element; N], GetManyMutError<N>>;
unsafe fn get_many_unchecked_mut<const N: usize>(
&mut self,
indices: [usize; N],
) -> [&mut Self::Element; N];
}
Expand description
Extension trait for get_many_mut
.
Required Associated Types§
Required Methods§
Sourcefn get_many_mut<const N: usize>(
&mut self,
indices: [usize; N],
) -> Result<[&mut Self::Element; N], GetManyMutError<N>>
fn get_many_mut<const N: usize>( &mut self, indices: [usize; N], ) -> Result<[&mut Self::Element; N], GetManyMutError<N>>
Returns mutable references to many indices at once.
Returns an error if any index is out-of-bounds, or if the same index was passed more than once.
§Examples
use get_many_mut::GetManyMutExt;
let v = &mut [1, 2, 3];
if let Ok([a, b]) = v.get_many_mut([0, 2]) {
*a = 413;
*b = 612;
}
assert_eq!(v, &[413, 2, 612]);
ⓘ
use get_many_mut::GetManyMutExt;
let v = &mut [1, 2, 3];
v.get_many_mut([0, 2, 0]).unwrap();
Sourceunsafe fn get_many_unchecked_mut<const N: usize>(
&mut self,
indices: [usize; N],
) -> [&mut Self::Element; N]
unsafe fn get_many_unchecked_mut<const N: usize>( &mut self, indices: [usize; N], ) -> [&mut Self::Element; N]
Returns mutable references to many indices at once, without doing any checks.
For a safe alternative see get_many_mut
.
§Safety
Calling this method with overlapping or out-of-bounds indices is undefined behavior even if the resulting references are not used.
§Examples
use get_many_mut::GetManyMutExt;
let x = &mut [1, 2, 4];
unsafe {
let [a, b] = x.get_many_unchecked_mut([0, 2]);
*a *= 10;
*b *= 100;
}
assert_eq!(x, &[10, 2, 400]);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.