Skip to content

Commit c2ddbdb

Browse files
y86-devojeda
authored andcommitted
rust: pin-init: call try_[pin_]init! from [pin_]init! instead of __init_internal!
The `[pin_]init!` macros have the same behavior as the `try_[pin_]init!` macros, except that they set the error type to `Infallible`. Instead of calling the primitive `__init_internal!` with the correct parameters, the same can thus be achieved by calling `try_[pin_]init!`. Since this makes it more clear what their behavior is, simplify the implementations of `[pin_]init!`. Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Fiona Behrens <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Tested-by: Andreas Hindborg <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 84837cf commit c2ddbdb

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

rust/pin-init/src/lib.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -676,16 +676,9 @@ macro_rules! pin_init {
676676
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
677677
$($fields:tt)*
678678
}) => {
679-
$crate::__init_internal!(
680-
@this($($this)?),
681-
@typ($t $(::<$($generics),*>)?),
682-
@fields($($fields)*),
683-
@error(::core::convert::Infallible),
684-
@data(PinData, use_data),
685-
@has_data(HasPinData, __pin_data),
686-
@construct_closure(pin_init_from_closure),
687-
@munch_fields($($fields)*),
688-
)
679+
$crate::try_pin_init!($(&$this in)? $t $(::<$($generics),*>)? {
680+
$($fields)*
681+
}? ::core::convert::Infallible)
689682
};
690683
}
691684

@@ -784,16 +777,9 @@ macro_rules! init {
784777
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
785778
$($fields:tt)*
786779
}) => {
787-
$crate::__init_internal!(
788-
@this($($this)?),
789-
@typ($t $(::<$($generics),*>)?),
790-
@fields($($fields)*),
791-
@error(::core::convert::Infallible),
792-
@data(InitData, /*no use_data*/),
793-
@has_data(HasInitData, __init_data),
794-
@construct_closure(init_from_closure),
795-
@munch_fields($($fields)*),
796-
)
780+
$crate::try_init!($(&$this in)? $t $(::<$($generics),*>)? {
781+
$($fields)*
782+
}? ::core::convert::Infallible)
797783
}
798784
}
799785

0 commit comments

Comments
 (0)