]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: pin-init: add `#[default_error(<type>)]` attribute to initializer macros
authorBenno Lossin <lossin@kernel.org>
Fri, 16 Jan 2026 10:54:25 +0000 (11:54 +0100)
committerBenno Lossin <lossin@kernel.org>
Sat, 17 Jan 2026 09:51:42 +0000 (10:51 +0100)
commitaeabc92eb2d8c27578274a7ec3d0d00558fedfc2
treeb90dee22d567510997fa6397a2b4199c951dc62c
parent4883830e9784bdf6223fe0e5f1ea36d4a4ab4fef
rust: pin-init: add `#[default_error(<type>)]` attribute to initializer macros

The `#[default_error(<type>)]` attribute can be used to supply a default
type as the error used for the `[pin_]init!` macros. This way one can
easily define custom `try_[pin_]init!` variants that default to your
project specific error type. Just write the following declarative macro:

    macro_rules! try_init {
        ($($args:tt)*) => {
            ::pin_init::init!(
                #[default_error(YourCustomErrorType)]
                $($args)*
            )
        }
    }

Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <lossin@kernel.org>
rust/pin-init/internal/src/init.rs