[−][src]Struct inplace_it::SliceMemoryGuard
Guard-struct used for correctly initialize uninitialized memory and drop
it when guard goes out of scope.
Usually, you should not use this struct to handle your memory.
Safety
If you use this struct manually, remember: &mut [MaybeUninit<T>]
's content will be overwriten while initialization.
So it is not safe to apply this struct to already initialized data and it can lead to memory leaks.
Example
use inplace_it::SliceMemoryGuard; use std::mem::MaybeUninit; // Placing uninitialized memory let mut memory: [MaybeUninit<usize>; 100] = unsafe { MaybeUninit::uninit().assume_init() }; // Initializing guard let mut memory_guard = unsafe { SliceMemoryGuard::new( // Borrowing memory &mut memory, // Forwarding initializer |index| index * 2 ) }; // For now, memory contains content like [0, 2, 4, 6, ..., 196, 198] // Using memory // Sum of [0, 2, 4, 6, ..., 196, 198] = sum of [0, 1, 2, 3, ..., 98, 99] * 2 = ( 99 * (99+1) ) / 2 * 2 let sum: usize = memory_guard.iter().sum(); assert_eq!(sum, 99 * 100);
Implementations
impl<'a, T> SliceMemoryGuard<'a, T>
[src][−]
pub unsafe fn new(
memory: &'a mut [MaybeUninit<T>],
init: impl FnMut(usize) -> T
) -> Self
[src][−]
memory: &'a mut [MaybeUninit<T>],
init: impl FnMut(usize) -> T
) -> Self
Initialize memory guard
Trait Implementations
impl<'a, T> Deref for SliceMemoryGuard<'a, T>
[src][+]
impl<'a, T> DerefMut for SliceMemoryGuard<'a, T>
[src][+]
impl<'a, T> Drop for SliceMemoryGuard<'a, T>
[src][+]
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for SliceMemoryGuard<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T> Send for SliceMemoryGuard<'a, T> where
T: Send,
T: Send,
impl<'a, T> Sync for SliceMemoryGuard<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Unpin for SliceMemoryGuard<'a, T>
impl<'a, T> !UnwindSafe for SliceMemoryGuard<'a, T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,