diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 535 |
1 files changed, 268 insertions, 267 deletions
@@ -309,32 +309,10 @@ macro_rules! pin_project { // - no useful error messages. (wontfix) // etc... -// Not public API. #[doc(hidden)] #[macro_export] -macro_rules! __pin_project_internal { - // macro helpers - // ignores any projection without a projection identity - (@make_proj_ty; - [] // no identity given, so we ignore the projection - $($field:tt)* - ) => {}; - // ignores make_proj_replace_ty without a projection identity - (@make_proj_replace_ty; - [] // no identity given, so we ignore the projection - $($field:tt)* - ) => {}; - (@$struct_ty_ident:ident=>make_proj_method; - [] - $($variant:tt)* - ) => {}; - (@$struct_ty_ident:ident=>make_proj_replace_method; - [] - $($field:tt)* - ) => {}; - // ============================================================================================= - // struct:main - (@expand; +macro_rules! __pin_project_expand { + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] @@ -347,7 +325,7 @@ macro_rules! __pin_project_internal { } $(impl $($pinned_drop:tt)*)? ) => { - $crate::__pin_project_internal! { @reconstruct; + $crate::__pin_project_reconstruct! { [$(#[$attrs])* $vis $struct_ty_ident $ident] [$($def_generics)*] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] @@ -356,35 +334,35 @@ macro_rules! __pin_project_internal { } } - $crate::__pin_project_internal! { @make_proj_ty; + $crate::__pin_project_make_proj_ty! { [$($proj_mut_ident)?] [$proj_vis $struct_ty_ident $ident] - [make_proj_field_mut] + [__pin_project_make_proj_field_mut] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $($body_data)* } } - $crate::__pin_project_internal! { @make_proj_ty; + $crate::__pin_project_make_proj_ty! { [$($proj_ref_ident)?] [$proj_vis $struct_ty_ident $ident] - [make_proj_field_ref] + [__pin_project_make_proj_field_ref] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $($body_data)* } } - $crate::__pin_project_internal! { @make_proj_replace_ty; + $crate::__pin_project_make_proj_replace_ty! { [$($proj_replace_ident)?] [$proj_vis $struct_ty_ident] - [make_proj_field_replace] + [__pin_project_make_proj_field_replace] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $($body_data)* } } - $crate::__pin_project_internal! { @constant; + $crate::__pin_project_constant! { [$(#[$attrs])* $vis $struct_ty_ident $ident] [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] [$proj_vis] @@ -396,7 +374,12 @@ macro_rules! __pin_project_internal { $(impl $($pinned_drop)*)? } }; - (@constant; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_constant { + ( [$(#[$attrs:meta])* $vis:vis struct $ident:ident] [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] [$proj_vis:vis] @@ -410,7 +393,6 @@ macro_rules! __pin_project_internal { } $(impl $($pinned_drop:tt)*)? ) => { - #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 // This lint warns of `clippy::*` generated by external macros. @@ -419,10 +401,10 @@ macro_rules! __pin_project_internal { #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. #[allow(clippy::used_underscore_binding)] const _: () = { - $crate::__pin_project_internal! { @make_proj_ty; + $crate::__pin_project_make_proj_ty! { [$($proj_mut_ident)? Projection] [$proj_vis struct $ident] - [make_proj_field_mut] + [__pin_project_make_proj_field_mut] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $( @@ -431,10 +413,10 @@ macro_rules! __pin_project_internal { ),+ } } - $crate::__pin_project_internal! { @make_proj_ty; + $crate::__pin_project_make_proj_ty! { [$($proj_ref_ident)? ProjectionRef] [$proj_vis struct $ident] - [make_proj_field_ref] + [__pin_project_make_proj_field_ref] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $( @@ -448,7 +430,7 @@ macro_rules! __pin_project_internal { $(where $($where_clause)*)? { - $crate::__pin_project_internal! { @struct=>make_proj_method; + $crate::__pin_project_struct_make_proj_method! { [$($proj_mut_ident)? Projection] [$proj_vis] [project get_unchecked_mut mut] @@ -460,7 +442,7 @@ macro_rules! __pin_project_internal { ),+ } } - $crate::__pin_project_internal! { @struct=>make_proj_method; + $crate::__pin_project_struct_make_proj_method! { [$($proj_ref_ident)? ProjectionRef] [$proj_vis] [project_ref get_ref] @@ -472,7 +454,7 @@ macro_rules! __pin_project_internal { ),+ } } - $crate::__pin_project_internal! { @struct=>make_proj_replace_method; + $crate::__pin_project_struct_make_proj_replace_method! { [$($proj_replace_ident)?] [$proj_vis] [ProjectionReplace] @@ -486,17 +468,17 @@ macro_rules! __pin_project_internal { } } - $crate::__pin_project_internal! { @make_unpin_impl; + $crate::__pin_project_make_unpin_impl! { [$vis $ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] $( - $field: $crate::__pin_project_internal!(@make_unpin_bound; + $field: $crate::__pin_project_make_unpin_bound!( $(#[$pin])? $field_ty ) ),+ } - $crate::__pin_project_internal! { @make_drop_impl; + $crate::__pin_project_make_drop_impl! { [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] $(impl $($pinned_drop)*)? @@ -533,9 +515,7 @@ macro_rules! __pin_project_internal { } }; }; - // ============================================================================================= - // enum:main - (@constant; + ( [$(#[$attrs:meta])* $vis:vis enum $ident:ident] [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] [$proj_vis:vis] @@ -554,7 +534,6 @@ macro_rules! __pin_project_internal { } $(impl $($pinned_drop:tt)*)? ) => { - #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 // This lint warns of `clippy::*` generated by external macros. // We allow this lint for compatibility with older compilers. @@ -565,7 +544,7 @@ macro_rules! __pin_project_internal { $(where $($where_clause)*)? { - $crate::__pin_project_internal! { @enum=>make_proj_method; + $crate::__pin_project_enum_make_proj_method! { [$($proj_mut_ident)?] [$proj_vis] [project get_unchecked_mut mut] @@ -581,7 +560,7 @@ macro_rules! __pin_project_internal { ),+ } } - $crate::__pin_project_internal! { @enum=>make_proj_method; + $crate::__pin_project_enum_make_proj_method! { [$($proj_ref_ident)?] [$proj_vis] [project_ref get_ref] @@ -597,7 +576,7 @@ macro_rules! __pin_project_internal { ),+ } } - $crate::__pin_project_internal! { @enum=>make_proj_replace_method; + $crate::__pin_project_enum_make_proj_replace_method! { [$($proj_replace_ident)?] [$proj_vis] [$($ty_generics)*] @@ -614,13 +593,13 @@ macro_rules! __pin_project_internal { } } - $crate::__pin_project_internal! { @make_unpin_impl; + $crate::__pin_project_make_unpin_impl! { [$vis $ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] $( $variant: ($( $( - $crate::__pin_project_internal!(@make_unpin_bound; + $crate::__pin_project_make_unpin_bound!( $(#[$pin])? $field_ty ) ),+ @@ -628,7 +607,7 @@ macro_rules! __pin_project_internal { ),+ } - $crate::__pin_project_internal! { @make_drop_impl; + $crate::__pin_project_make_drop_impl! { [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] $(impl $($pinned_drop)*)? @@ -638,8 +617,12 @@ macro_rules! __pin_project_internal { // since it does not apply to enums. }; }; +} - (@reconstruct; +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_reconstruct { + ( [$(#[$attrs:meta])* $vis:vis struct $ident:ident] [$($def_generics:tt)*] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] @@ -660,9 +643,7 @@ macro_rules! __pin_project_internal { ),+ } }; - - // reconstruct original enum type - (@reconstruct; + ( [$(#[$attrs:meta])* $vis:vis enum $ident:ident] [$($def_generics:tt)*] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] @@ -693,62 +674,22 @@ macro_rules! __pin_project_internal { ),+ } }; - // construct a projected type - (@make_proj_ty; - [$proj_ty_ident:ident] - [$proj_vis:vis $struct_ty_ident:ident $ident:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] - [$($body_data:tt)+] - ) => { - #[allow(dead_code)] // This lint warns unused fields/variants. - #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 - // This lint warns of `clippy::*` generated by external macros. - // We allow this lint for compatibility with older compilers. - #[allow(clippy::unknown_clippy_lints)] - #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) - #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. - #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref) - #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 - $proj_vis $struct_ty_ident $proj_ty_ident <'__pin, $($impl_generics)*> - where - $ident <$($ty_generics)*>: '__pin - $(, $($where_clause)*)? - { - $($body_data)+ - } - }; - // construct a project_replace type - (@make_proj_replace_ty; - [$proj_ty_ident:ident] - [$proj_vis:vis $struct_ty_ident:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] - [$($body_data:tt)+] - ) => { - #[allow(dead_code)] // This lint warns unused fields/variants. - #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 - #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) - #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. - #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 - $proj_vis $struct_ty_ident $proj_ty_ident <$($impl_generics)*> - where - $($($where_clause)*)? - { - $($body_data)+ - } - }; - // ============================================================================================= - // struct:make_proj_ty - // if a proj_ty_ident was given, we do *not* create one with the default - (@make_proj_ty; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_ty { + ([] $($field:tt)*) => {}; + ( [$proj_ty_ident:ident $default_ident:ident] [$proj_vis:vis struct $ident:ident] $($field:tt)* ) => {}; - (@make_proj_ty; + ( [$proj_ty_ident:ident] [$proj_vis:vis struct $ident:ident] - [$make_proj_field:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] { $( $(#[$pin:ident])? @@ -756,51 +697,24 @@ macro_rules! __pin_project_internal { ),+ $(,)? } ) => { - $crate::__pin_project_internal!{@make_proj_ty; + $crate::__pin_project_make_proj_ty_body! { [$proj_ty_ident] [$proj_vis struct $ident] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] - [ - $( - $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; - $(#[$pin])? $field_ty - ) - ),+ - ] - } - }; - (@make_proj_replace_ty; - [$proj_ty_ident:ident] - [$proj_vis:vis struct] - [$make_proj_field:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] - { - $( - $(#[$pin:ident])? - $field_vis:vis $field:ident: $field_ty:ty - ),+ $(,)? - } - ) => { - $crate::__pin_project_internal!{@make_proj_replace_ty; - [$proj_ty_ident] - [$proj_vis struct] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] [ $( - $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; + $field_vis $field: $crate::$__pin_project_make_proj_field!( $(#[$pin])? $field_ty ) ),+ ] } }; - // ============================================================================================= - // enum:make_proj_ty - (@make_proj_ty; + ( [$proj_ty_ident:ident] [$proj_vis:vis enum $ident:ident] - [$make_proj_field:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] { $( $(#[$variant_attrs:meta])* @@ -813,15 +727,15 @@ macro_rules! __pin_project_internal { ),+ $(,)? } ) => { - $crate::__pin_project_internal!{@make_proj_ty; + $crate::__pin_project_make_proj_ty_body! { [$proj_ty_ident] [$proj_vis enum $ident] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] [ $( $variant $({ $( - $field: $crate::__pin_project_internal!(@$make_proj_field; + $field: $crate::$__pin_project_make_proj_field!( $(#[$pin])? $field_ty ) ),+ @@ -830,11 +744,70 @@ macro_rules! __pin_project_internal { ] } }; - (@make_proj_replace_ty; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_ty_body { + ( + [$proj_ty_ident:ident] + [$proj_vis:vis $struct_ty_ident:ident $ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + [$($body_data:tt)+] + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref) + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis $struct_ty_ident $proj_ty_ident <'__pin, $($impl_generics)*> + where + $ident <$($ty_generics)*>: '__pin + $(, $($where_clause)*)? + { + $($body_data)+ + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_replace_ty { + ([] $($field:tt)*) => {}; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis struct] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + ) => { + $crate::__pin_project_make_proj_replace_ty_body! { + [$proj_ty_ident] + [$proj_vis struct] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [ + $( + $field_vis $field: $crate::$__pin_project_make_proj_field!( + $(#[$pin])? $field_ty + ) + ),+ + ] + } + }; + ( [$proj_ty_ident:ident] [$proj_vis:vis enum] - [$make_proj_field:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] { $( $(#[$variant_attrs:meta])* @@ -847,15 +820,15 @@ macro_rules! __pin_project_internal { ),+ $(,)? } ) => { - $crate::__pin_project_internal!{@make_proj_replace_ty; + $crate::__pin_project_make_proj_replace_ty_body! { [$proj_ty_ident] [$proj_vis enum] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] [ $( $variant $({ $( - $field: $crate::__pin_project_internal!(@$make_proj_field; + $field: $crate::$__pin_project_make_proj_field!( $(#[$pin])? $field_ty ) ),+ @@ -864,9 +837,36 @@ macro_rules! __pin_project_internal { ] } }; - // ============================================================================================= - (@make_proj_replace_block; - [$($proj_path: tt)+] +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_replace_ty_body { + ( + [$proj_ty_ident:ident] + [$proj_vis:vis $struct_ty_ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + [$($body_data:tt)+] + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis $struct_ty_ident $proj_ty_ident <$($impl_generics)*> + where + $($($where_clause)*)? + { + $($body_data)+ + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_replace_block { + ( + [$($proj_path:tt)+] { $( $(#[$pin:ident])? @@ -876,7 +876,7 @@ macro_rules! __pin_project_internal { ) => { let result = $($proj_path)* { $( - $field: $crate::__pin_project_internal!(@make_replace_field_proj; + $field: $crate::__pin_project_make_replace_field_proj!( $(#[$pin])? $field ) ),+ @@ -884,7 +884,7 @@ macro_rules! __pin_project_internal { { ( $( - $crate::__pin_project_internal!(@make_unsafe_drop_in_place_guard; + $crate::__pin_project_make_unsafe_drop_in_place_guard!( $(#[$pin])? $field ), )* ); @@ -892,23 +892,21 @@ macro_rules! __pin_project_internal { result }; - (@make_proj_replace_block; - [$($proj_path: tt)+] - ) => { - $($proj_path)* - }; + ([$($proj_path:tt)+]) => { $($proj_path)* }; +} - // ============================================================================================= - // struct:make_proj_method - // this employs an ignored default strategy that ensures the identity used matches the one used in `struct=>make_proj_ty` - (@struct=>make_proj_method; +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_struct_make_proj_method { + ([] $($variant:tt)*) => {}; + ( [$proj_ty_ident:ident $_ignored_default_arg:ident] [$proj_vis:vis] [$method_ident:ident $get_method:ident $($mut:ident)?] [$($ty_generics:tt)*] $($variant:tt)* ) => { - $crate::__pin_project_internal! { @struct=>make_proj_method; + $crate::__pin_project_struct_make_proj_method! { [$proj_ty_ident] [$proj_vis] [$method_ident $get_method $($mut)?] @@ -916,7 +914,7 @@ macro_rules! __pin_project_internal { $($variant)* } }; - (@struct=>make_proj_method; + ( [$proj_ty_ident:ident] [$proj_vis:vis] [$method_ident:ident $get_method:ident $($mut:ident)?] @@ -935,7 +933,7 @@ macro_rules! __pin_project_internal { let Self { $($field),* } = self.$get_method(); $proj_ty_ident { $( - $field: $crate::__pin_project_internal!(@make_unsafe_field_proj; + $field: $crate::__pin_project_make_unsafe_field_proj!( $(#[$pin])? $field ) ),+ @@ -943,8 +941,13 @@ macro_rules! __pin_project_internal { } } }; +} - (@struct=>make_proj_replace_method; +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_struct_make_proj_replace_method { + ([] $($field:tt)*) => {}; + ( [$proj_ty_ident:ident] [$proj_vis:vis] [$_proj_ty_ident:ident] @@ -969,7 +972,7 @@ macro_rules! __pin_project_internal { let Self { $($field),* } = &mut *__self_ptr; - $crate::__pin_project_internal!{@make_proj_replace_block; + $crate::__pin_project_make_proj_replace_block! { [$proj_ty_ident] { $( @@ -981,9 +984,13 @@ macro_rules! __pin_project_internal { } } }; - // ============================================================================================= - // enum:make_proj_method - (@enum=>make_proj_method; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_enum_make_proj_method { + ([] $($variant:tt)*) => {}; + ( [$proj_ty_ident:ident] [$proj_vis:vis] [$method_ident:ident $get_method:ident $($mut:ident)?] @@ -1010,8 +1017,7 @@ macro_rules! __pin_project_internal { })? => { $proj_ty_ident::$variant $({ $( - $field: $crate::__pin_project_internal!( - @make_unsafe_field_proj; + $field: $crate::__pin_project_make_unsafe_field_proj!( $(#[$pin])? $field ) ),+ @@ -1022,7 +1028,13 @@ macro_rules! __pin_project_internal { } } }; - (@enum=>make_proj_replace_method; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_enum_make_proj_replace_method { + ([] $($field:tt)*) => {}; + ( [$proj_ty_ident:ident] [$proj_vis:vis] [$($ty_generics:tt)*] @@ -1053,7 +1065,7 @@ macro_rules! __pin_project_internal { Self::$variant $({ $($field),+ })? => { - $crate::__pin_project_internal!{@make_proj_replace_block; + $crate::__pin_project_make_proj_replace_block! { [$proj_ty_ident :: $variant] $({ $( @@ -1068,11 +1080,14 @@ macro_rules! __pin_project_internal { } } }; - // ============================================================================================= - // make_unpin_impl - (@make_unpin_impl; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unpin_impl { + ( [$vis:vis $ident:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] $($field:tt)* ) => { // Automatically create the appropriate conditional `Unpin` implementation. @@ -1115,12 +1130,14 @@ macro_rules! __pin_project_internal { { } }; +} - // ============================================================================================= - // make_drop_impl - (@make_drop_impl; +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_drop_impl { + ( [$_ident:ident] - [$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)* )?] + [$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)*)?] impl $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? $( $generics:ident @@ -1202,9 +1219,9 @@ macro_rules! __pin_project_internal { } } }; - (@make_drop_impl; + ( [$ident:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] ) => { // Ensure that struct does not implement `Drop`. // @@ -1224,103 +1241,88 @@ macro_rules! __pin_project_internal { { } }; +} - // ============================================================================================= - // make_unpin_bound - (@make_unpin_bound; - #[pin] - $field_ty:ty - ) => { +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unpin_bound { + (#[pin] $field_ty:ty) => { $field_ty }; - (@make_unpin_bound; - $field_ty:ty - ) => { + ($field_ty:ty) => { $crate::__private::AlwaysUnpin<$field_ty> }; +} - // ============================================================================================= - // make_unsafe_field_proj - (@make_unsafe_field_proj; - #[pin] - $field:ident - ) => { +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unsafe_field_proj { + (#[pin] $field:ident) => { $crate::__private::Pin::new_unchecked($field) }; - (@make_unsafe_field_proj; - $field:ident - ) => { + ($field:ident) => { $field }; +} - // ============================================================================================= - // make_replace_field_proj - (@make_replace_field_proj; - #[pin] - $field:ident - ) => { +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_replace_field_proj { + (#[pin] $field:ident) => { $crate::__private::PhantomData }; - (@make_replace_field_proj; - $field:ident - ) => { + ($field:ident) => { $crate::__private::ptr::read($field) }; +} - - // ============================================================================================= - // make_unsafe_drop_in_place_guard - (@make_unsafe_drop_in_place_guard; - #[pin] - $field:ident - ) => { +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unsafe_drop_in_place_guard { + (#[pin] $field:ident) => { $crate::__private::UnsafeDropInPlaceGuard::new($field) }; - (@make_unsafe_drop_in_place_guard; - $field:ident - ) => { + ($field:ident) => { () }; +} - // ============================================================================================= - // make_proj_field - (@make_proj_field_mut; - #[pin] - $field_ty:ty - ) => { +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_field_mut { + (#[pin] $field_ty:ty) => { $crate::__private::Pin<&'__pin mut ($field_ty)> }; - (@make_proj_field_mut; - $field_ty:ty - ) => { + ($field_ty:ty) => { &'__pin mut ($field_ty) }; - (@make_proj_field_ref; - #[pin] - $field_ty:ty - ) => { +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_field_ref { + (#[pin] $field_ty:ty) => { $crate::__private::Pin<&'__pin ($field_ty)> }; - (@make_proj_field_ref; - $field_ty:ty - ) => { + ($field_ty:ty) => { &'__pin ($field_ty) }; +} - (@make_proj_field_replace; - #[pin] - $field_ty:ty - ) => { +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_field_replace { + (#[pin] $field_ty:ty) => { $crate::__private::PhantomData<$field_ty> }; - (@make_proj_field_replace; - $field_ty:ty - ) => { + ($field_ty:ty) => { $field_ty }; +} - // ============================================================================================= - // Parses attributes and determines visibility +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_internal { // parsing proj_mut_ident ( [] @@ -1339,9 +1341,8 @@ macro_rules! __pin_project_internal { $($tt)* } }; - // parsing proj_ref_ident - { + ( [$($proj_mut_ident:ident)?] [] [$($proj_replace_ident:ident)?] @@ -1349,7 +1350,7 @@ macro_rules! __pin_project_internal { #[project_ref = $proj_ref_ident:ident] $($tt:tt)* - } => { + ) => { $crate::__pin_project_internal! { [$($proj_mut_ident)?] [$proj_ref_ident] @@ -1358,9 +1359,8 @@ macro_rules! __pin_project_internal { $($tt)* } }; - // parsing proj_replace_ident - { + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [] @@ -1368,7 +1368,7 @@ macro_rules! __pin_project_internal { #[project_replace = $proj_replace_ident:ident] $($tt:tt)* - } => { + ) => { $crate::__pin_project_internal! { [$($proj_mut_ident)?] [$($proj_ref_ident)?] @@ -1377,10 +1377,9 @@ macro_rules! __pin_project_internal { $($tt)* } }; - // this is actually part of a recursive step that picks off a single non-`pin_project_lite` attribute // there could be more to parse - { + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] @@ -1388,7 +1387,7 @@ macro_rules! __pin_project_internal { #[$($attr:tt)*] $($tt:tt)* - } => { + ) => { $crate::__pin_project_internal! { [$($proj_mut_ident)?] [$($proj_ref_ident)?] @@ -1397,18 +1396,17 @@ macro_rules! __pin_project_internal { $($tt)* } }; - // now determine visibility // if public, downgrade - { + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] [$($attrs:tt)*] pub $struct_ty_ident:ident $ident:ident $($tt:tt)* - } => { - $crate::__pin_project_internal! { + ) => { + $crate::__pin_project_parse_generics! { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] @@ -1417,15 +1415,15 @@ macro_rules! __pin_project_internal { $($tt)* } }; - { + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] [$($attrs:tt)*] $vis:vis $struct_ty_ident:ident $ident:ident $($tt:tt)* - } => { - $crate::__pin_project_internal! { + ) => { + $crate::__pin_project_parse_generics! { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] @@ -1434,7 +1432,11 @@ macro_rules! __pin_project_internal { $($tt)* } }; - // parse generics +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_parse_generics { ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] @@ -1462,7 +1464,7 @@ macro_rules! __pin_project_internal { } $(impl $($pinned_drop:tt)*)? ) => { - $crate::__pin_project_internal! { @expand; + $crate::__pin_project_expand! { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] @@ -1499,7 +1501,6 @@ macro_rules! __pin_project_internal { }; } -// Not public API. #[doc(hidden)] pub mod __private { use core::mem::ManuallyDrop; |