Text of rust.docs.kernel.org › next › kernel › macro.try_init.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

try_init in kernel - Rust

Skip to main content try_init kernel Macro try_ init Source macro_rules! try_init { ($($args:tt)*) => { ... }; } Expand description Construct an in-place fallible initializer for struct s. This macro defaults the error to Error . If you need Infallible , then use init! . The syntax is identical to try_pin_init! . If you want to specify a custom error, append ? $type after the struct initializer. The safety caveats from try_pin_init! 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. § Examples use kernel::error::Error; use pin_init::init_zeroed; struct BigBuf { big: KBox<[u8; 1024 * 1024 * 1024 ]>, small: [u8; 1024 * 1024 ], } impl BigBuf { fn new() -> impl Init< Self , Error> { try_init! ( Self { big: KBox::init(init_zeroed(), GFP_KERNEL) ? , small: [ 0 ; 1024 * 1024 ], } ?

Error) } }