]> git.ipfire.org Git - thirdparty/linux.git/commit
add `[pin_]init_scope` to execute code before creating an initializer
authorBenno Lossin <lossin@kernel.org>
Thu, 16 Oct 2025 21:05:39 +0000 (23:05 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Mon, 20 Oct 2025 22:40:12 +0000 (00:40 +0200)
commitfc2b38de4c01710ecb9ebb9ecdce9a7bf433e9a8
tree1c21a203d799fa2402e60803665a949e11cebd49
parente6901808a3b28d8bdabfa98a618b2eab6f8798e8
add `[pin_]init_scope` to execute code before creating an initializer

In more complex cases, initializers need to run arbitrary code before
assigning initializers to fields. While this is possible using the
underscore codeblock feature (`_: {}`), values returned by such
functions cannot be used from later field initializers.

The two new functions `[pin_]init_scope` allow users to first run some
fallible code and then return an initializer which the function turns
into a single initializer. This permits using the same value multiple
times by different fields.

Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
[ Fix typo in commit message: s/functinos/functions/. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/pin-init/src/lib.rs