macro_rules! init {
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
$($fields:tt)*
}) => { ... };
}
Expand description
Construct an in-place initializer for struct
s.
This macro defaults the error to Infallible
. If you need a different error, then use
try_init!
.
The syntax is identical to pin_init!
and its safety caveats also apply:
unsafe
code 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, zeroed};
struct BigBuf {
small: [u8; 1024 * 1024],
}
impl BigBuf {
fn new() -> impl Init<Self> {
init!(Self {
small <- zeroed(),
})
}
}