init!() { /* proc-macro */ }Expand description
Construct an in-place, fallible initializer for structs.
This macro defaults the error to Infallible; if you need a different one, write ? Error
at the end, after the struct initializer.
The syntax is identical to pin_init! and its safety caveats also apply:
unsafecode must guarantee either full initialization or return an error and allow deallocation of the memory.- the fields are initialized in the order given in the initializer.
- no references to fields are allowed to be created inside of the initializer.
This initializer is for initializing data in-place that might later be moved. If you want to
pin-initialize, use pin_init!.
ยงExamples
use pin_init::{init, Init, init_zeroed};
struct BigBuf {
small: [u8; 1024 * 1024],
}
impl BigBuf {
fn new() -> impl Init<Self> {
init!(Self {
small <- init_zeroed(),
})
}
}