Skip to main content

Initialize

Trait Initialize 

Source
pub trait Initialize: Sized {
    // Required method
    fn initialize() -> Self;

    // Provided method
    unsafe fn initialize_raw(data: *mut ()) { ... }
}
Expand description

Writes a default value through a raw pointer.

Type-erased containers cannot call Default::default, so they call Initialize::initialize_raw through a function pointer. Implemented for every Default type.

Required Methods§

Source

fn initialize() -> Self

Returns the initial value of this type.

Provided Methods§

Source

unsafe fn initialize_raw(data: *mut ())

Writes the initial value into already allocated memory.

§Safety

data must be non-null, writable and aligned for Self, and must not hold an initialized value already (the old value is overwritten without being dropped).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Initialize for T
where T: Default,