From c3667ead3b804a91e1476c4696ad12e866eca72b Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Fri, 7 Jun 2024 13:30:28 +0300 Subject: [PATCH 1/7] Derive macros `derive_phantom_data` implementation skeleton --- module/core/derive_tools_meta/Cargo.toml | 3 ++ module/core/derive_tools_meta/src/derive.rs | 2 + .../src/derive/phantom_data.rs | 22 ++++++++ module/core/derive_tools_meta/src/lib.rs | 52 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 module/core/derive_tools_meta/src/derive/phantom_data.rs diff --git a/module/core/derive_tools_meta/Cargo.toml b/module/core/derive_tools_meta/Cargo.toml index eade555900..0de9875c41 100644 --- a/module/core/derive_tools_meta/Cargo.toml +++ b/module/core/derive_tools_meta/Cargo.toml @@ -40,6 +40,7 @@ default = [ "derive_as_ref", "derive_as_mut", "derive_variadic_from", + "derive_phantom_data" ] full = [ "enabled", @@ -51,6 +52,7 @@ full = [ "derive_as_ref", "derive_as_mut", "derive_variadic_from", + "derive_phantom_data" ] enabled = [ "macro_tools/enabled", "iter_tools/enabled", "former_types/enabled" ] @@ -62,6 +64,7 @@ derive_from = [] derive_new = [] derive_inner_from = [] derive_variadic_from = [] +derive_phantom_data = [] [dependencies] # xxx : qqq : optimize features set diff --git a/module/core/derive_tools_meta/src/derive.rs b/module/core/derive_tools_meta/src/derive.rs index 5008fe2fab..774239addb 100644 --- a/module/core/derive_tools_meta/src/derive.rs +++ b/module/core/derive_tools_meta/src/derive.rs @@ -26,3 +26,5 @@ pub mod new; pub mod variadic_from; #[ cfg( feature = "derive_reflect" ) ] pub mod reflect; +#[ cfg( feature = "derive_phantom_data" ) ] +pub mod phantom_data; diff --git a/module/core/derive_tools_meta/src/derive/phantom_data.rs b/module/core/derive_tools_meta/src/derive/phantom_data.rs new file mode 100644 index 0000000000..48a2aa4c31 --- /dev/null +++ b/module/core/derive_tools_meta/src/derive/phantom_data.rs @@ -0,0 +1,22 @@ +use super::*; +use macro_tools::{diag, Result, syn::ItemStruct, attr}; +use macro_tools::phantom::add_to_item; +use macro_tools::quote::ToTokens; + +pub fn phantom_data( input : proc_macro::TokenStream ) -> Result +{ + let original_input = input.clone(); + let parsed = syn::parse::< ItemStruct >( input )?; + let has_debug = attr::has_debug( parsed.attrs.iter() )?; + let item_name = &parsed.ident; + + let result = add_to_item( &parsed ).to_token_stream(); + + if has_debug + { + let about = format!( "derive : PhantomData\nstructure : {item_name}" ); + diag::report_print( about, &original_input, &result ); + } + + Ok( result ) +} \ No newline at end of file diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index f9b255f8ff..facda23c3f 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -15,6 +15,7 @@ feature = "derive_from", feature = "derive_inner_from", feature = "derive_variadic_from", + feature = "derive_phantom_data" ) )] #[ cfg( feature = "enabled" ) ] @@ -30,6 +31,7 @@ mod derive; // feature = "derive_from", // feature = "derive_inner_from", // feature = "derive_variadic_from", +// feature = "derive_phantom_data" // ) // )] // #[ cfg( feature = "enabled" ) ] @@ -517,3 +519,53 @@ pub fn derive_variadic_from( input : proc_macro::TokenStream ) -> proc_macro::To Err( err ) => err.to_compile_error().into(), } } + +/// +/// Provides an automatic `PhantomData` field for a struct based on its generic types. +/// +/// This macro simplifies the addition of a `PhantomData` field to a struct +/// to indicate that the struct logically owns instances of the generic types, +/// even though it does not store them. +/// +/// ## Example Usage +/// +/// Instead of manually adding `PhantomData` to `MyStruct`: +/// +/// ```rust +/// use std::marker::PhantomData; +/// +/// pub struct MyStruct +/// { +/// data: i32, +/// _phantom: PhantomData, +/// } +/// +/// ``` +/// +/// Use `#[ derive( PhantomData ) ]` to automatically generate the `PhantomData` field: +/// +/// ```rust +/// use derive_tools_meta::*; +/// +/// #[ derive( PhantomData ) ] +/// pub struct MyStruct< T > +/// { +/// data: i32, +/// } +/// ``` +/// +/// The macro facilitates the addition of the `PhantomData` field without additional boilerplate code. +/// + +#[ cfg( feature = "enabled" ) ] +#[ cfg ( feature = "derive_phantom_data" ) ] +#[ proc_macro_derive( PhantomData, attributes( debug ) ) ] +pub fn derive_phantom_data( input : proc_macro::TokenStream ) -> proc_macro::TokenStream +{ + let result = derive::phantom_data::phantom_data( input ); + match result + { + Ok( stream ) => stream.into(), + Err( err ) => err.to_compile_error().into(), + } +} From 08342ada3c626f00cf7b579124cc25120f428044 Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Fri, 7 Jun 2024 13:43:56 +0300 Subject: [PATCH 2/7] Formating --- .../src/derive/phantom_data.rs | 33 +++++++++++-------- module/core/derive_tools_meta/src/lib.rs | 1 - 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/module/core/derive_tools_meta/src/derive/phantom_data.rs b/module/core/derive_tools_meta/src/derive/phantom_data.rs index 48a2aa4c31..3074cd93be 100644 --- a/module/core/derive_tools_meta/src/derive/phantom_data.rs +++ b/module/core/derive_tools_meta/src/derive/phantom_data.rs @@ -1,22 +1,27 @@ use super::*; -use macro_tools::{diag, Result, syn::ItemStruct, attr}; -use macro_tools::phantom::add_to_item; -use macro_tools::quote::ToTokens; +use macro_tools::{ + attr, + diag, + Result, + phantom::add_to_item, + quote::ToTokens, + syn::ItemStruct, +}; pub fn phantom_data( input : proc_macro::TokenStream ) -> Result { - let original_input = input.clone(); - let parsed = syn::parse::< ItemStruct >( input )?; - let has_debug = attr::has_debug( parsed.attrs.iter() )?; - let item_name = &parsed.ident; + let original_input = input.clone(); + let parsed = syn::parse::< ItemStruct >( input )?; + let has_debug = attr::has_debug( parsed.attrs.iter() )?; + let item_name = &parsed.ident; - let result = add_to_item( &parsed ).to_token_stream(); + let result = add_to_item( &parsed ).to_token_stream(); - if has_debug - { - let about = format!( "derive : PhantomData\nstructure : {item_name}" ); - diag::report_print( about, &original_input, &result ); - } + if has_debug + { + let about = format!( "derive : PhantomData\nstructure : {item_name}" ); + diag::report_print( about, &original_input, &result ); + } - Ok( result ) + Ok( result ) } \ No newline at end of file diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index facda23c3f..3ae5883435 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -539,7 +539,6 @@ pub fn derive_variadic_from( input : proc_macro::TokenStream ) -> proc_macro::To /// data: i32, /// _phantom: PhantomData, /// } -/// /// ``` /// /// Use `#[ derive( PhantomData ) ]` to automatically generate the `PhantomData` field: From aef100cd95fdd1d7e69d2286051a4187d85f443f Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Mon, 10 Jun 2024 15:00:14 +0300 Subject: [PATCH 3/7] Changed macro type to attribute --- module/core/derive_tools_meta/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index 3ae5883435..e34dfd083e 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -541,12 +541,12 @@ pub fn derive_variadic_from( input : proc_macro::TokenStream ) -> proc_macro::To /// } /// ``` /// -/// Use `#[ derive( PhantomData ) ]` to automatically generate the `PhantomData` field: +/// Use `#[ phantom_data ]` to automatically generate the `PhantomData` field: /// /// ```rust /// use derive_tools_meta::*; /// -/// #[ derive( PhantomData ) ] +/// #[ phantom_data ] /// pub struct MyStruct< T > /// { /// data: i32, @@ -558,8 +558,8 @@ pub fn derive_variadic_from( input : proc_macro::TokenStream ) -> proc_macro::To #[ cfg( feature = "enabled" ) ] #[ cfg ( feature = "derive_phantom_data" ) ] -#[ proc_macro_derive( PhantomData, attributes( debug ) ) ] -pub fn derive_phantom_data( input : proc_macro::TokenStream ) -> proc_macro::TokenStream +#[ proc_macro_attribute ] +pub fn phantom_data( _attr: proc_macro::TokenStream, input : proc_macro::TokenStream ) -> proc_macro::TokenStream { let result = derive::phantom_data::phantom_data( input ); match result From 2dc8b98ffa3ff8a69b2de9fecd2957e1fddd1d23 Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Mon, 10 Jun 2024 17:23:17 +0300 Subject: [PATCH 4/7] Named structs test --- module/core/derive_tools/Cargo.toml | 6 ++++++ module/core/derive_tools/tests/inc/mod.rs | 11 +++++++++++ .../tests/inc/phantom_data/only_test/struct_named.rs | 5 +++++ .../tests/inc/phantom_data/struct_named.rs | 11 +++++++++++ .../tests/inc/phantom_data/struct_named_manual.rs | 12 ++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs create mode 100644 module/core/derive_tools/tests/inc/phantom_data/struct_named.rs create mode 100644 module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index 3f2b08fe4b..660683bd19 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -69,6 +69,8 @@ default = [ "derive_inner_from", "derive_new", + "derive_phantom_data" + # "use_std", ] @@ -114,6 +116,8 @@ full = [ "derive_inner_from", "derive_new", + "derive_phantom_data" + # "use_std", ] no_std = [] @@ -174,6 +178,8 @@ derive_from = [ "derive_tools_meta/derive_from" ] derive_inner_from = [ "derive_tools_meta/derive_inner_from" ] derive_new = [ "derive_tools_meta/derive_new" ] +derive_phantom_data = [ "derive_tools_meta/derive_phantom_data" ] + parse_display = [ "parse-display" ] [dependencies] diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index a79deeb407..ce18dc6d12 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -25,6 +25,7 @@ mod all_manual_test; feature = "derive_deref_mut", feature = "derive_from", feature = "derive_inner_from", + feature = "derive_phantom_data" ) )] mod all_test; @@ -245,3 +246,13 @@ mod inner_from_tests mod multiple_unnamed_test; } + +#[ cfg( feature = "derive_phantom_data" ) ] +#[ path = "phantom_data" ] +mod phantom_data_tests { +#[ allow( unused_imports ) ] + use super::*; + + mod struct_named; + mod struct_named_manual; +} diff --git a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs b/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs new file mode 100644 index 0000000000..3683625610 --- /dev/null +++ b/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs @@ -0,0 +1,5 @@ +#[ test ] +fn phantom_data() +{ + let _ = StructNamed::< bool >{ a : "boo".into(), b : 3, _phantom: Default::default() }; +} \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs b/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs new file mode 100644 index 0000000000..0919d9e076 --- /dev/null +++ b/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs @@ -0,0 +1,11 @@ +use super::*; + +#[ allow( dead_code ) ] +#[ the_module::phantom_data ] +struct StructNamed +{ + a : String, + b : i32, +} + +include!("./only_test/struct_named.rs"); \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs b/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs new file mode 100644 index 0000000000..f397ed26d1 --- /dev/null +++ b/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs @@ -0,0 +1,12 @@ +use super::*; +use std::marker::PhantomData; + +#[ allow( dead_code ) ] +struct StructNamed +{ + a : String, + b : i32, + _phantom : PhantomData, +} + +include!("./only_test/struct_named.rs"); \ No newline at end of file From be871759e654fa643f896ad938d1c4da480fe3f5 Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Mon, 10 Jun 2024 17:26:24 +0300 Subject: [PATCH 5/7] Tuple structs test --- module/core/derive_tools/tests/inc/mod.rs | 2 ++ .../tests/inc/phantom_data/only_test/struct_tuple.rs | 5 +++++ .../derive_tools/tests/inc/phantom_data/struct_tuple.rs | 7 +++++++ .../tests/inc/phantom_data/struct_tuple_manual.rs | 7 +++++++ 4 files changed, 21 insertions(+) create mode 100644 module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs create mode 100644 module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs create mode 100644 module/core/derive_tools/tests/inc/phantom_data/struct_tuple_manual.rs diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index ce18dc6d12..e478614c8e 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -255,4 +255,6 @@ mod phantom_data_tests { mod struct_named; mod struct_named_manual; + mod struct_tuple; + mod struct_tuple_manual; } diff --git a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs b/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs new file mode 100644 index 0000000000..f4984638ad --- /dev/null +++ b/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs @@ -0,0 +1,5 @@ +#[ test ] +fn phantom_data() +{ + let _ = StructTuple::< bool >( "boo".into(), 3, Default::default() ); +} diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs b/module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs new file mode 100644 index 0000000000..dfcfbd8d99 --- /dev/null +++ b/module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs @@ -0,0 +1,7 @@ +use super::*; + +#[ allow( dead_code ) ] +#[ the_module::phantom_data ] +struct StructTuple< T >( String, i32 ); + +include!( "./only_test/struct_tuple.rs" ); \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_tuple_manual.rs b/module/core/derive_tools/tests/inc/phantom_data/struct_tuple_manual.rs new file mode 100644 index 0000000000..250c208a35 --- /dev/null +++ b/module/core/derive_tools/tests/inc/phantom_data/struct_tuple_manual.rs @@ -0,0 +1,7 @@ +use std::marker::PhantomData; +use super::*; + +#[ allow( dead_code ) ] +struct StructTuple< T >( String, i32, PhantomData< T > ); + +include!( "./only_test/struct_tuple.rs" ); \ No newline at end of file From 59c53c9200f4a5c81984e790a9f4c34f8d5b340c Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Mon, 10 Jun 2024 18:35:35 +0300 Subject: [PATCH 6/7] Formating --- module/core/derive_tools/tests/inc/mod.rs | 5 +++-- .../inc/phantom_data/only_test/struct_tuple.rs | 2 +- .../tests/inc/phantom_data/struct_named.rs | 4 ++-- .../inc/phantom_data/struct_named_manual.rs | 6 +++--- .../src/derive/phantom_data.rs | 17 +++++++++-------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index e478614c8e..88100202b1 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -249,8 +249,9 @@ mod inner_from_tests #[ cfg( feature = "derive_phantom_data" ) ] #[ path = "phantom_data" ] -mod phantom_data_tests { -#[ allow( unused_imports ) ] +mod phantom_data_tests +{ + #[ allow( unused_imports ) ] use super::*; mod struct_named; diff --git a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs b/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs index f4984638ad..4ba6b070a0 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs +++ b/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs @@ -1,5 +1,5 @@ #[ test ] fn phantom_data() { - let _ = StructTuple::< bool >( "boo".into(), 3, Default::default() ); + let _ = StructTuple::< bool >( "boo".into(), 3, Default::default() ); } diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs b/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs index 0919d9e076..81eb88efa2 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs +++ b/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs @@ -2,10 +2,10 @@ use super::*; #[ allow( dead_code ) ] #[ the_module::phantom_data ] -struct StructNamed +struct StructNamed< T > { a : String, b : i32, } -include!("./only_test/struct_named.rs"); \ No newline at end of file +include!( "./only_test/struct_named.rs" ); \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs b/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs index f397ed26d1..0099e18962 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs +++ b/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs @@ -2,11 +2,11 @@ use super::*; use std::marker::PhantomData; #[ allow( dead_code ) ] -struct StructNamed +struct StructNamed< T > { a : String, b : i32, - _phantom : PhantomData, + _phantom : PhantomData< T >, } -include!("./only_test/struct_named.rs"); \ No newline at end of file +include!( "./only_test/struct_named.rs" ); \ No newline at end of file diff --git a/module/core/derive_tools_meta/src/derive/phantom_data.rs b/module/core/derive_tools_meta/src/derive/phantom_data.rs index 3074cd93be..87efa86921 100644 --- a/module/core/derive_tools_meta/src/derive/phantom_data.rs +++ b/module/core/derive_tools_meta/src/derive/phantom_data.rs @@ -1,14 +1,15 @@ use super::*; -use macro_tools::{ - attr, - diag, - Result, - phantom::add_to_item, - quote::ToTokens, - syn::ItemStruct, +use macro_tools:: +{ + attr, + diag, + Result, + phantom::add_to_item, + quote::ToTokens, + syn::ItemStruct, }; -pub fn phantom_data( input : proc_macro::TokenStream ) -> Result +pub fn phantom_data( input : proc_macro::TokenStream ) -> Result< proc_macro2::TokenStream > { let original_input = input.clone(); let parsed = syn::parse::< ItemStruct >( input )?; From bd599f603ded6361305b27846efff4d3689f348d Mon Sep 17 00:00:00 2001 From: Dmytro Kriuchkov Date: Mon, 10 Jun 2024 18:51:47 +0300 Subject: [PATCH 7/7] Renamed feature --- module/core/derive_tools/Cargo.toml | 6 +++--- module/core/derive_tools/tests/inc/mod.rs | 8 ++++---- .../only_test/struct_named.rs | 2 +- .../only_test/struct_tuple.rs | 2 +- .../inc/{phantom_data => phantom}/struct_named.rs | 2 +- .../struct_named_manual.rs | 0 .../inc/{phantom_data => phantom}/struct_tuple.rs | 2 +- .../struct_tuple_manual.rs | 0 module/core/derive_tools_meta/Cargo.toml | 6 +++--- module/core/derive_tools_meta/src/derive.rs | 4 ++-- .../src/derive/{phantom_data.rs => phantom.rs} | 2 +- module/core/derive_tools_meta/src/lib.rs | 14 +++++++------- 12 files changed, 24 insertions(+), 24 deletions(-) rename module/core/derive_tools/tests/inc/{phantom_data => phantom}/only_test/struct_named.rs (82%) rename module/core/derive_tools/tests/inc/{phantom_data => phantom}/only_test/struct_tuple.rs (78%) rename module/core/derive_tools/tests/inc/{phantom_data => phantom}/struct_named.rs (77%) rename module/core/derive_tools/tests/inc/{phantom_data => phantom}/struct_named_manual.rs (100%) rename module/core/derive_tools/tests/inc/{phantom_data => phantom}/struct_tuple.rs (77%) rename module/core/derive_tools/tests/inc/{phantom_data => phantom}/struct_tuple_manual.rs (100%) rename module/core/derive_tools_meta/src/derive/{phantom_data.rs => phantom.rs} (81%) diff --git a/module/core/derive_tools/Cargo.toml b/module/core/derive_tools/Cargo.toml index 660683bd19..4e74117b3d 100644 --- a/module/core/derive_tools/Cargo.toml +++ b/module/core/derive_tools/Cargo.toml @@ -69,7 +69,7 @@ default = [ "derive_inner_from", "derive_new", - "derive_phantom_data" + "derive_phantom" # "use_std", ] @@ -116,7 +116,7 @@ full = [ "derive_inner_from", "derive_new", - "derive_phantom_data" + "derive_phantom" # "use_std", ] @@ -178,7 +178,7 @@ derive_from = [ "derive_tools_meta/derive_from" ] derive_inner_from = [ "derive_tools_meta/derive_inner_from" ] derive_new = [ "derive_tools_meta/derive_new" ] -derive_phantom_data = [ "derive_tools_meta/derive_phantom_data" ] +derive_phantom = [ "derive_tools_meta/derive_phantom" ] parse_display = [ "parse-display" ] diff --git a/module/core/derive_tools/tests/inc/mod.rs b/module/core/derive_tools/tests/inc/mod.rs index 88100202b1..65ed82361a 100644 --- a/module/core/derive_tools/tests/inc/mod.rs +++ b/module/core/derive_tools/tests/inc/mod.rs @@ -25,7 +25,7 @@ mod all_manual_test; feature = "derive_deref_mut", feature = "derive_from", feature = "derive_inner_from", - feature = "derive_phantom_data" + feature = "derive_phantom" ) )] mod all_test; @@ -247,9 +247,9 @@ mod inner_from_tests } -#[ cfg( feature = "derive_phantom_data" ) ] -#[ path = "phantom_data" ] -mod phantom_data_tests +#[ cfg( feature = "derive_phantom" ) ] +#[ path = "phantom" ] +mod phantom_tests { #[ allow( unused_imports ) ] use super::*; diff --git a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs b/module/core/derive_tools/tests/inc/phantom/only_test/struct_named.rs similarity index 82% rename from module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs rename to module/core/derive_tools/tests/inc/phantom/only_test/struct_named.rs index 3683625610..a1d823498d 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_named.rs +++ b/module/core/derive_tools/tests/inc/phantom/only_test/struct_named.rs @@ -1,5 +1,5 @@ #[ test ] -fn phantom_data() +fn phantom() { let _ = StructNamed::< bool >{ a : "boo".into(), b : 3, _phantom: Default::default() }; } \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs b/module/core/derive_tools/tests/inc/phantom/only_test/struct_tuple.rs similarity index 78% rename from module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs rename to module/core/derive_tools/tests/inc/phantom/only_test/struct_tuple.rs index 4ba6b070a0..a54f6e6636 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/only_test/struct_tuple.rs +++ b/module/core/derive_tools/tests/inc/phantom/only_test/struct_tuple.rs @@ -1,5 +1,5 @@ #[ test ] -fn phantom_data() +fn phantom() { let _ = StructTuple::< bool >( "boo".into(), 3, Default::default() ); } diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs b/module/core/derive_tools/tests/inc/phantom/struct_named.rs similarity index 77% rename from module/core/derive_tools/tests/inc/phantom_data/struct_named.rs rename to module/core/derive_tools/tests/inc/phantom/struct_named.rs index 81eb88efa2..51ba45b723 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/struct_named.rs +++ b/module/core/derive_tools/tests/inc/phantom/struct_named.rs @@ -1,7 +1,7 @@ use super::*; #[ allow( dead_code ) ] -#[ the_module::phantom_data ] +#[ the_module::phantom ] struct StructNamed< T > { a : String, diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs b/module/core/derive_tools/tests/inc/phantom/struct_named_manual.rs similarity index 100% rename from module/core/derive_tools/tests/inc/phantom_data/struct_named_manual.rs rename to module/core/derive_tools/tests/inc/phantom/struct_named_manual.rs diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs b/module/core/derive_tools/tests/inc/phantom/struct_tuple.rs similarity index 77% rename from module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs rename to module/core/derive_tools/tests/inc/phantom/struct_tuple.rs index dfcfbd8d99..d19af977f8 100644 --- a/module/core/derive_tools/tests/inc/phantom_data/struct_tuple.rs +++ b/module/core/derive_tools/tests/inc/phantom/struct_tuple.rs @@ -1,7 +1,7 @@ use super::*; #[ allow( dead_code ) ] -#[ the_module::phantom_data ] +#[ the_module::phantom ] struct StructTuple< T >( String, i32 ); include!( "./only_test/struct_tuple.rs" ); \ No newline at end of file diff --git a/module/core/derive_tools/tests/inc/phantom_data/struct_tuple_manual.rs b/module/core/derive_tools/tests/inc/phantom/struct_tuple_manual.rs similarity index 100% rename from module/core/derive_tools/tests/inc/phantom_data/struct_tuple_manual.rs rename to module/core/derive_tools/tests/inc/phantom/struct_tuple_manual.rs diff --git a/module/core/derive_tools_meta/Cargo.toml b/module/core/derive_tools_meta/Cargo.toml index 0de9875c41..1eddaf68b8 100644 --- a/module/core/derive_tools_meta/Cargo.toml +++ b/module/core/derive_tools_meta/Cargo.toml @@ -40,7 +40,7 @@ default = [ "derive_as_ref", "derive_as_mut", "derive_variadic_from", - "derive_phantom_data" + "derive_phantom" ] full = [ "enabled", @@ -52,7 +52,7 @@ full = [ "derive_as_ref", "derive_as_mut", "derive_variadic_from", - "derive_phantom_data" + "derive_phantom" ] enabled = [ "macro_tools/enabled", "iter_tools/enabled", "former_types/enabled" ] @@ -64,7 +64,7 @@ derive_from = [] derive_new = [] derive_inner_from = [] derive_variadic_from = [] -derive_phantom_data = [] +derive_phantom = [] [dependencies] # xxx : qqq : optimize features set diff --git a/module/core/derive_tools_meta/src/derive.rs b/module/core/derive_tools_meta/src/derive.rs index 774239addb..1cce024835 100644 --- a/module/core/derive_tools_meta/src/derive.rs +++ b/module/core/derive_tools_meta/src/derive.rs @@ -26,5 +26,5 @@ pub mod new; pub mod variadic_from; #[ cfg( feature = "derive_reflect" ) ] pub mod reflect; -#[ cfg( feature = "derive_phantom_data" ) ] -pub mod phantom_data; +#[ cfg( feature = "derive_phantom" ) ] +pub mod phantom; diff --git a/module/core/derive_tools_meta/src/derive/phantom_data.rs b/module/core/derive_tools_meta/src/derive/phantom.rs similarity index 81% rename from module/core/derive_tools_meta/src/derive/phantom_data.rs rename to module/core/derive_tools_meta/src/derive/phantom.rs index 87efa86921..0246cf240b 100644 --- a/module/core/derive_tools_meta/src/derive/phantom_data.rs +++ b/module/core/derive_tools_meta/src/derive/phantom.rs @@ -9,7 +9,7 @@ use macro_tools:: syn::ItemStruct, }; -pub fn phantom_data( input : proc_macro::TokenStream ) -> Result< proc_macro2::TokenStream > +pub fn phantom( input : proc_macro::TokenStream ) -> Result< proc_macro2::TokenStream > { let original_input = input.clone(); let parsed = syn::parse::< ItemStruct >( input )?; diff --git a/module/core/derive_tools_meta/src/lib.rs b/module/core/derive_tools_meta/src/lib.rs index e34dfd083e..3940855ac6 100644 --- a/module/core/derive_tools_meta/src/lib.rs +++ b/module/core/derive_tools_meta/src/lib.rs @@ -15,7 +15,7 @@ feature = "derive_from", feature = "derive_inner_from", feature = "derive_variadic_from", - feature = "derive_phantom_data" + feature = "derive_phantom" ) )] #[ cfg( feature = "enabled" ) ] @@ -31,7 +31,7 @@ mod derive; // feature = "derive_from", // feature = "derive_inner_from", // feature = "derive_variadic_from", -// feature = "derive_phantom_data" +// feature = "derive_phantom" // ) // )] // #[ cfg( feature = "enabled" ) ] @@ -541,12 +541,12 @@ pub fn derive_variadic_from( input : proc_macro::TokenStream ) -> proc_macro::To /// } /// ``` /// -/// Use `#[ phantom_data ]` to automatically generate the `PhantomData` field: +/// Use `#[ phantom ]` to automatically generate the `PhantomData` field: /// /// ```rust /// use derive_tools_meta::*; /// -/// #[ phantom_data ] +/// #[ phantom ] /// pub struct MyStruct< T > /// { /// data: i32, @@ -557,11 +557,11 @@ pub fn derive_variadic_from( input : proc_macro::TokenStream ) -> proc_macro::To /// #[ cfg( feature = "enabled" ) ] -#[ cfg ( feature = "derive_phantom_data" ) ] +#[ cfg ( feature = "derive_phantom" ) ] #[ proc_macro_attribute ] -pub fn phantom_data( _attr: proc_macro::TokenStream, input : proc_macro::TokenStream ) -> proc_macro::TokenStream +pub fn phantom( _attr: proc_macro::TokenStream, input : proc_macro::TokenStream ) -> proc_macro::TokenStream { - let result = derive::phantom_data::phantom_data( input ); + let result = derive::phantom::phantom( input ); match result { Ok( stream ) => stream.into(),