pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
// Provided method
fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E> { ... }
}Expand description
An initializer for T.
To use this initializer, you will need a suitable memory location that can hold a T. This can
be Box<T>, Arc<T> or even the stack (see stack_pin_init!). Because
PinInit<T, E> is a super trait, you can use every function that takes it as well.
Also see the module description.
§Safety
When implementing this trait you will need to take great care. Also there are probably very few
cases where a manual implementation is necessary. Use init_from_closure where possible.
The PinInit::__init function must work without the pinning requirement; the caller is
allowed to move the pointee after initialization.
Provided Methods§
Sourcefn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
First initializes the value using self then calls the function f with the initialized
value.
If f returns an error the value is dropped and the initializer will forward the error.
§Examples
use pin_init::{init, init_zeroed, Init};
struct Foo {
buf: [u8; 1_000_000],
}
impl Foo {
fn setup(&mut self) {
println!("Setting up foo");
}
}
let foo = init!(Foo {
buf <- init_zeroed()
}).chain(|foo| {
foo.setup();
Ok(())
});Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".