[][src]Struct inplace_it::SliceMemoryGuard

pub struct SliceMemoryGuard<'a, T> { /* fields omitted */ }

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]

Initialize memory guard

Trait Implementations

impl<'a, T> Deref for SliceMemoryGuard<'a, T>[src]

type Target = [T]

The resulting type after dereferencing.

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

impl<'a, T> Send for SliceMemoryGuard<'a, T> where
    T: Send

impl<'a, T> Sync for SliceMemoryGuard<'a, T> where
    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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.