pub trait AssumeInit {
type Output;
// Required method
unsafe fn assume_init(self) -> Self::Output;
}Expand description
Trait for converting collections of uninitialized (MaybeUninit<T>) values
to collections of corresponding initializes values (T).
§Example
use std::mem::MaybeUninit;
use rten_tensor::AssumeInit;
fn scale_values<'a>(dst: &'a mut [MaybeUninit<f32>], src: &[f32], scale: f32) -> &'a mut [f32] {
for (y, x) in dst.into_iter().zip(src) {
y.write(x * scale);
}
// Safety: All elements have been initialized.
unsafe { dst.assume_init() }
}
let src = [1., 2., 3.];
let mut dst = [MaybeUninit::uninit(); 3];
let scaled = scale_values(&mut dst, &src, 2.);
assert_eq!(scaled, [2., 4., 6.]);Required Associated Types§
Required Methods§
Sourceunsafe fn assume_init(self) -> Self::Output
unsafe fn assume_init(self) -> Self::Output
Cast self to a collection of initialized values.
§Safety
The caller must guarantee that all elements have been initialized.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".