diff --git a/Cargo.toml b/Cargo.toml index 1753b4f..807fb8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quick-impl" -version = "0.1.3" +version = "0.1.4" edition = "2021" repository = "https://github.com/makcandrov/quick-impl" homepage = "https://github.com/makcandrov/quick-impl" diff --git a/README.md b/README.md index ab1ec0a..cbd77c0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # quick-impl -`quick-impl` is a Rust procedural macro that simplifies working with enums and structures by generating common methods and traits for each variant/field. This helps reduce boilerplate code and enhances the ergonomics of using enums and structures in your Rust projects. +`quick-impl` is a Rust procedural macro that simplifies working with enums and structs by generating common methods and traits for each variant or field. This helps reduce boilerplate code and enhances the ergonomics of using enums and structs in your Rust projects. ## Features @@ -9,9 +9,10 @@ - `as_ref` - Returns an immutable reference to the associated data of the enum variant. - `as_ref_mut` - Returns a mutable reference to the associated data of the enum variant. - `from` - Creates an instance of the enum variant from the associated data. -- `into` - Converts the enum into the variant associated data, returning an [`Option`]. +- `into` - Converts the enum into the associated data of the variant, returning an [`Option`]. - `is` - Checks if the enum variant matches a specified variant. -- `try_into` - Converts the enum into the variant associated data, returning a [`Result`]. +- `set` - Replaces the current instance with a new instance of the specified variant. +- `try_into` - Converts the enum into the associated data of the variant, returning a [`Result`]. ### Enums traits @@ -23,11 +24,11 @@ - `get` - A getter for the field. Returns a reference to the field. - `get_clone` - A getter for the field. Returns a clone of the field. -- `get_mut` - A mutable getter for the field. -- `into` - Converts the structure into the field. +- `get_mut` - A mutable getter for a field. +- `into` - Converts the struct into the field. - `set` - A setter for the field. - `take` - Returns the field and replaces it with its default value. -- `with` - Returns the sutrcture with the field modified. +- `with` - Returns the struct with the field modified. ### Structures traits @@ -66,6 +67,7 @@ use quick_impl::QuickImpl; enum YourEnum { #[quick_impl(pub const is)] Variant1, + #[quick_impl(pub as_ref, pub(crate) as_ref_mut, impl From)] Variant2(i32), // ... add attributes to other variants as needed @@ -82,6 +84,6 @@ fn main() { } ``` -More examples can be found in [examples]. +More examples can be found in the [examples]. [examples]: https://github.com/makcandrov/quick-impl/tree/main/examples diff --git a/examples/config.rs b/examples/config.rs new file mode 100644 index 0000000..664b662 --- /dev/null +++ b/examples/config.rs @@ -0,0 +1,41 @@ +use quick_impl::QuickImpl; + +#[derive(QuickImpl, Default)] +struct Config { + #[quick_impl(pub get, pub set, take, pub with)] + host: String, + + #[quick_impl(pub get, pub set, take, pub with)] + port: u16, + + #[quick_impl(pub get, pub set, take, pub with)] + max_connections: usize, +} + +fn main() { + // Using the `Default` trait to create a Config instance + let mut config = Config::default(); + + // Setting values + config.set_host("localhost".to_string()); + config.set_port(8080); + config.set_max_connections(100); + + assert_eq!(config.get_host(), "localhost"); + assert_eq!(*config.get_port(), 8080); + assert_eq!(*config.get_max_connections(), 100); + + // Using `take` to retrieve and reset fields + let host = config.take_host(); + assert_eq!(host, "localhost"); + assert_eq!(config.get_host(), ""); // After `take`, it should be default (empty String) + + let port = config.take_port(); + assert_eq!(port, 8080); + assert_eq!(*config.get_port(), 0); // After `take`, it should be default (0) + + // Using `with` to modify fields fluently + let new_config = config.with_host("127.0.0.1".to_string()).with_port(3000); + assert_eq!(new_config.get_host(), "127.0.0.1"); + assert_eq!(*new_config.get_port(), 3000); +} diff --git a/examples/person.rs b/examples/person.rs index bb8de06..d8d67c2 100644 --- a/examples/person.rs +++ b/examples/person.rs @@ -4,6 +4,7 @@ use quick_impl::QuickImpl; struct Person { #[quick_impl(pub get)] name: String, + #[quick_impl(pub get, pub set, get_mut)] age: u32, } diff --git a/examples/shapes.rs b/examples/shapes.rs index f789c7f..00ba71c 100644 --- a/examples/shapes.rs +++ b/examples/shapes.rs @@ -4,10 +4,13 @@ use quick_impl::QuickImpl; pub enum Shape { #[quick_impl(pub const is)] Circle(f64), + #[quick_impl(pub as_ref, as_ref_mut, impl From)] Rectangle(f64, f64), + #[quick_impl(pub as_ref, as_ref_mut, pub into)] Square(f64), + #[quick_impl(pub const from = "create_cuboid", pub const is, pub into)] Cuboid { width: f64, height: f64, depth: f64 }, } diff --git a/examples/status.rs b/examples/status.rs new file mode 100644 index 0000000..24bbaf0 --- /dev/null +++ b/examples/status.rs @@ -0,0 +1,47 @@ +use quick_impl::QuickImpl; + +#[derive(Debug, QuickImpl)] +pub enum Status { + #[quick_impl(pub const is)] + Pending, + + #[quick_impl(pub const is, pub try_into, impl TryInto)] + Approved(i32), + + #[quick_impl(pub const is, pub try_into, impl TryInto)] + Rejected(String), +} + +#[derive(QuickImpl)] +pub struct Wrapper { + #[quick_impl(impl Deref, impl DerefMut)] + data: Vec, +} + +fn main() { + // Enum example with `try_into` and `is` + let status = Status::Approved(200); + assert!(status.is_approved()); + + // Use `try_into` to convert to the associated data + let approved_code: Result = status.try_into_approved(); + assert_eq!(approved_code.unwrap(), 200); + + let rejected_status = Status::Rejected("Invalid request".to_string()); + assert!(rejected_status.is_rejected()); + + let rejection_reason: Result = rejected_status.try_into(); + assert_eq!(rejection_reason.unwrap(), "Invalid request"); + + // Struct example with `Deref` and `DerefMut` + let mut wrapper = Wrapper { + data: vec![1, 2, 3], + }; + + // Accessing inner `Vec` through Deref + assert_eq!(wrapper.len(), 3); // Calls `Vec::len` + + // Mutating inner `Vec` through DerefMut + wrapper.push(4); + assert_eq!(wrapper.len(), 4); // Now has 4 elements +} diff --git a/examples/web_event.rs b/examples/web_event.rs index a48b60e..8000a6c 100644 --- a/examples/web_event.rs +++ b/examples/web_event.rs @@ -4,12 +4,16 @@ use quick_impl::QuickImpl; pub enum WebEvent { #[quick_impl(pub const is)] PageLoad, + #[quick_impl(pub const is)] PageUnload, + #[quick_impl(pub as_ref, pub(crate) as_ref_mut, impl From)] KeyPress(char), + #[quick_impl(pub as_ref, pub(crate) as_ref_mut, pub into)] Paste(String), + #[quick_impl(pub from = "click_from_coordinates", pub const is, pub as_ref)] Click { x: i64, y: i64 }, } diff --git a/src/components/enums/methods/as_ref.rs b/src/components/enums/methods/as_ref.rs index b18f49e..f34c1b7 100644 --- a/src/components/enums/methods/as_ref.rs +++ b/src/components/enums/methods/as_ref.rs @@ -10,7 +10,7 @@ use crate::tokens::{destructure_data, destructure_types, get_delimiter}; build_enum_name! { ConfigName, "as_{}" } build_enum_doc! { ConfigDoc, - "Returns an immutable reference to the associated data if it is the [`{}::{}`] variant. Otherwise, returns `None`.", + "Returns an immutable reference to the associated data if the variant is [`{}::{}`]. Otherwise, returns `None`.", } build_config! { diff --git a/src/components/enums/methods/as_ref_mut.rs b/src/components/enums/methods/as_ref_mut.rs index 9d2c673..19e3cd9 100644 --- a/src/components/enums/methods/as_ref_mut.rs +++ b/src/components/enums/methods/as_ref_mut.rs @@ -10,7 +10,7 @@ use crate::tokens::{destructure_data, destructure_types, get_delimiter}; build_enum_name! { ConfigName, "as_{}_mut" } build_enum_doc! { ConfigDoc, - "Returns a mutable reference to the associated data if it is the [`{}::{}`] variant. Otherwise, returns `None`.", + "Returns a mutable reference to the associated data if the variant is [`{}::{}`]. Otherwise, returns `None`.", } build_config! { diff --git a/src/components/enums/methods/from.rs b/src/components/enums/methods/from.rs index 29e01d5..3cc1f15 100644 --- a/src/components/enums/methods/from.rs +++ b/src/components/enums/methods/from.rs @@ -10,7 +10,7 @@ use crate::tokens::{destructure_data, destructure_data_with_types, get_delimiter build_enum_name! { ConfigName, "from_{}" } build_enum_doc! { ConfigDoc, - "Creates a [`{}::{}`] variant from the associated data.", + "Creates a [`{}::{}`] variant from the provided data.", } build_config! { diff --git a/src/components/enums/methods/into.rs b/src/components/enums/methods/into.rs index fc18917..a172270 100644 --- a/src/components/enums/methods/into.rs +++ b/src/components/enums/methods/into.rs @@ -10,7 +10,7 @@ use crate::tokens::{destructure_data, destructure_types, get_delimiter}; build_enum_name! { ConfigName, "into_{}" } build_enum_doc! { ConfigDoc, - "Converts into the associated data if it is the [`{}::{}`] variant. Otherwise, returns `None`.", + "onverts to the associated data if the variant is [`{}::{}`]. Otherwise, returns `None`.", } build_config! { diff --git a/src/components/enums/methods/is.rs b/src/components/enums/methods/is.rs index 58f1632..0babc42 100644 --- a/src/components/enums/methods/is.rs +++ b/src/components/enums/methods/is.rs @@ -9,7 +9,7 @@ use crate::expand::Context; build_enum_name! { ConfigName, "is_{}" } build_enum_doc! { ConfigDoc, - "Returns `true` if it is the [`{}::{}`] variant. Otherwise, returns `false`.", + "Returns `true` if the variant is [`{}::{}`]. Otherwise, returns `false`.", } build_config! { diff --git a/src/components/enums/methods/mod.rs b/src/components/enums/methods/mod.rs index 6b061cf..b0276a0 100644 --- a/src/components/enums/methods/mod.rs +++ b/src/components/enums/methods/mod.rs @@ -13,5 +13,8 @@ pub use into::enum_method_into; mod is; pub use is::enum_method_is; +mod set; +pub use set::enum_method_set; + mod try_into; pub use try_into::enum_method_try_into; diff --git a/src/components/enums/methods/set.rs b/src/components/enums/methods/set.rs new file mode 100644 index 0000000..d0c7f91 --- /dev/null +++ b/src/components/enums/methods/set.rs @@ -0,0 +1,47 @@ +use proc_macro2::{Delimiter, TokenStream}; +use quote::quote; +use syn::Variant; + +use crate::attributes::{Attribute, MethodAttribute}; +use crate::config::{build_config, build_enum_doc, build_enum_name}; +use crate::expand::Context; +use crate::tokens::{destructure_data, destructure_data_with_types, get_delimiter}; + +build_enum_name! { ConfigName, "set_{}" } +build_enum_doc! { + ConfigDoc, + "Replaces the current instance with a new instance of the [`{}::{}`] variant, returning the original instance.", +} + +build_config! { + Config, + (name, ConfigName, true), + (doc, ConfigDoc, false), +} + +pub fn enum_method_set( + context: &Context, + variant: &Variant, + attribute: &Attribute, + method_attr: &MethodAttribute, +) -> syn::Result { + let config = Config::new(context, attribute, variant)?; + + let fields = &variant.fields; + let delimiter = get_delimiter(fields); + + let input = destructure_data_with_types(fields, quote! {}, Delimiter::None, false); + let destruct = destructure_data(fields, quote! {}, quote! {}, delimiter, true); + + let variant_ident = &variant.ident; + let keywords = method_attr.keywords(); + let doc = config.doc; + let method_ident = config.name; + + Ok(quote! { + #[doc = #doc] + #keywords fn #method_ident(&mut self, #input) -> Self { + ::core::mem::replace(self, Self:: #variant_ident #destruct ) + } + }) +} diff --git a/src/components/enums/methods/try_into.rs b/src/components/enums/methods/try_into.rs index 9787595..bfd3d0e 100644 --- a/src/components/enums/methods/try_into.rs +++ b/src/components/enums/methods/try_into.rs @@ -10,7 +10,7 @@ use crate::tokens::{destructure_data, destructure_types, get_delimiter}; build_enum_name! { ConfigName, "try_into_{}" } build_enum_doc! { ConfigDoc, - "Converts into the associated data if it is the [`{}::{}`] variant. Otherwise, returns `Err(self)`.", + "Converts to the associated data if the variant is [`{}::{}`]. Otherwise, returns `Err(self)`.", } build_config! { diff --git a/src/components/enums/mod.rs b/src/components/enums/mod.rs index 05c9477..af653af 100644 --- a/src/components/enums/mod.rs +++ b/src/components/enums/mod.rs @@ -1,20 +1,14 @@ -use methods::enum_method_try_into; use syn::DataEnum; -use traits::enum_trait_try_into; -use self::methods::{ - enum_method_as_ref, enum_method_as_ref_mut, enum_method_from, enum_method_into, enum_method_is, -}; -use self::traits::{enum_trait_default, enum_trait_from}; use crate::attributes::{AttributeType, Attributes}; use crate::expand::{Context, Implems}; -use crate::idents::methods::{ - METHOD_AS_REF, METHOD_AS_REF_MUT, METHOD_FROM, METHOD_INTO, METHOD_IS, METHOD_TRY_INTO, -}; -use crate::idents::traits::{TRAIT_DEFAULT, TRAIT_FROM, TRAIT_TRY_INTO}; +use crate::idents::{methods::*, traits::*}; mod methods; +use methods::*; + mod traits; +use traits::*; pub fn enum_impl( context: &Context<'_>, @@ -37,6 +31,7 @@ pub fn enum_impl( METHOD_FROM => enum_method_from(context, &variant, attribute, method_attr)?, METHOD_INTO => enum_method_into(context, &variant, attribute, method_attr)?, METHOD_IS => enum_method_is(context, &variant, attribute, method_attr)?, + METHOD_SET => enum_method_set(context, &variant, attribute, method_attr)?, METHOD_TRY_INTO => { enum_method_try_into(context, &variant, attribute, method_attr)? } diff --git a/src/components/enums/traits/from.rs b/src/components/enums/traits/from.rs index c5e6553..07431b6 100644 --- a/src/components/enums/traits/from.rs +++ b/src/components/enums/traits/from.rs @@ -9,7 +9,7 @@ use crate::tokens::{destructure_data, destructure_types, get_delimiter}; build_enum_doc! { ConfigDoc, - "Creates a [`{}::{}`] variant from the associated data.", + "Creates a [`{}::{}`] variant from the provided data.", } build_config! { diff --git a/src/components/enums/traits/try_into.rs b/src/components/enums/traits/try_into.rs index ab1a0d0..d3573ea 100644 --- a/src/components/enums/traits/try_into.rs +++ b/src/components/enums/traits/try_into.rs @@ -9,7 +9,7 @@ use crate::tokens::{destructure_data, destructure_types, get_delimiter}; build_enum_doc! { ConfigDoc, - "Converts into the associated data if it is the [`{}::{}`] variant. Otherwise, returns `Err(self)`.", + "Converts to the associated data if the variant is [`{}::{}`]. Otherwise, returns `Err(self)`.", } build_config! { diff --git a/src/components/structs/methods/get.rs b/src/components/structs/methods/get.rs index 2647584..99fa303 100644 --- a/src/components/structs/methods/get.rs +++ b/src/components/structs/methods/get.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "get_{}" } build_enum_doc! { ConfigDoc, - "A getter for the field `{1}` of [`{0}`].", + "A getter for the `{1}` field of [`{0}`].", } build_config! { diff --git a/src/components/structs/methods/get_clone.rs b/src/components/structs/methods/get_clone.rs index aa7a7ba..12b2e8b 100644 --- a/src/components/structs/methods/get_clone.rs +++ b/src/components/structs/methods/get_clone.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "get_{}" } build_enum_doc! { ConfigDoc, - "A getter for the field `{1}` of [`{0}`].", + "A getter for the `{1}` field of [`{0}`].", } build_config! { diff --git a/src/components/structs/methods/get_mut.rs b/src/components/structs/methods/get_mut.rs index 7d82051..b94e539 100644 --- a/src/components/structs/methods/get_mut.rs +++ b/src/components/structs/methods/get_mut.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "get_{}_mut" } build_enum_doc! { ConfigDoc, - "A mutable getter for the field `{1}` of [`{0}`].", + "A mutable getter for the `{1}` field of [`{0}`].", } build_config! { diff --git a/src/components/structs/methods/into.rs b/src/components/structs/methods/into.rs index 61e7aea..e9cbf1f 100644 --- a/src/components/structs/methods/into.rs +++ b/src/components/structs/methods/into.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "into_{}" } build_enum_doc! { ConfigDoc, - "Converts into the field `{1}` of [`{0}`].", + "Converts into the `{1}` field of [`{0}`].", } build_config! { diff --git a/src/components/structs/methods/set.rs b/src/components/structs/methods/set.rs index 8f08192..180c345 100644 --- a/src/components/structs/methods/set.rs +++ b/src/components/structs/methods/set.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "set_{}" } build_enum_doc! { ConfigDoc, - "A setter for the field `{1}` of [`{0}`]. Returns the old value.", + "A setter for the `{1}` field of [`{0}`]. Returns the previous value.", } build_config! { diff --git a/src/components/structs/methods/take.rs b/src/components/structs/methods/take.rs index fd42fba..9dbe05b 100644 --- a/src/components/structs/methods/take.rs +++ b/src/components/structs/methods/take.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "take_{}" } build_enum_doc! { ConfigDoc, - "Returns the field `{1}` of [`{0}`] and replaces it with its default value.", + "Returns the `{1}` field of [`{0}`] and replaces it with its default value.", } build_config! { diff --git a/src/components/structs/methods/with.rs b/src/components/structs/methods/with.rs index 869a657..93713ff 100644 --- a/src/components/structs/methods/with.rs +++ b/src/components/structs/methods/with.rs @@ -9,7 +9,7 @@ use crate::tokens::IndexedField; build_enum_name! { ConfigName, "with_{}" } build_enum_doc! { ConfigDoc, - "Changes the field `{1}` of the given [`{0}`] variable.", + "Returns an instance of [`{0}`] with the `{1}` field modified.", } build_config! { diff --git a/src/components/structs/traits/into.rs b/src/components/structs/traits/into.rs index aae3fc6..23c6b0a 100644 --- a/src/components/structs/traits/into.rs +++ b/src/components/structs/traits/into.rs @@ -8,7 +8,7 @@ use crate::tokens::IndexedField; build_enum_doc! { ConfigDoc, - "Converts into the field `{1}` of [`{0}`].", + "Converts into the `{1}` field of [`{0}`].", } build_config! { diff --git a/tests/test_enum.rs b/tests/test_enum.rs index 4ae3a81..fe31b76 100644 --- a/tests/test_enum.rs +++ b/tests/test_enum.rs @@ -4,7 +4,18 @@ use quick_impl::QuickImpl; fn test_enum_variant_unit() { #[derive(Debug, Eq, PartialEq, QuickImpl)] enum Test { - #[quick_impl(pub(crate) const is, const as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, pub try_into, impl Default, impl From, impl TryInto)] + #[quick_impl( + pub(crate) const is, + const as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A, } @@ -24,7 +35,18 @@ fn test_enum_variant_unit() { fn test_enum_variant_single_unnamed() { #[derive(Debug, Clone, Eq, PartialEq, QuickImpl)] enum Test { - #[quick_impl(pub(crate) const is, const as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, pub try_into, impl From, impl Default, impl TryInto)] + #[quick_impl( + pub(crate) const is, + const as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A(usize), } @@ -46,7 +68,18 @@ fn test_enum_variant_single_unnamed() { fn test_enum_variant_single_named() { #[derive(Debug, Eq, PartialEq, QuickImpl)] enum Test { - #[quick_impl(pub(crate) const is, const as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, impl From, impl Default, impl TryInto)] + #[quick_impl( + pub(crate) const is, + const as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A { a: usize }, } @@ -66,7 +99,18 @@ fn test_enum_variant_single_named() { fn test_enum_variant_multiple_unnamed() { #[derive(Debug, Eq, PartialEq, QuickImpl)] enum Test { - #[quick_impl(pub(crate) const is, const as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, impl From, impl Default, impl TryInto)] + #[quick_impl( + pub(crate) const is, + const as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A(usize, isize, char), } @@ -89,7 +133,18 @@ fn test_enum_variant_multiple_unnamed() { fn test_enum_variant_multiple_named() { #[derive(Debug, Eq, PartialEq, QuickImpl)] enum Test { - #[quick_impl(pub(crate) const is, const as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, impl From, impl Default, impl TryInto)] + #[quick_impl( + pub(crate) const is, + const as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A { a: usize, b: isize, c: char }, } @@ -131,8 +186,21 @@ fn test_enum_variant_multiple_named() { fn test_enum_generics() { #[derive(Debug, Eq, PartialEq, QuickImpl)] enum Test { - #[quick_impl(pub(crate) const is, const as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, impl From, impl Default, impl TryInto)] + #[quick_impl( + pub(crate) const is, + const as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A { a: T, b: U }, + #[allow(dead_code)] + B { a: T, b: U }, } let a = Test::A { @@ -160,7 +228,18 @@ fn test_enum_generics() { fn test_enum_lifetimes() { #[derive(Debug, Eq, PartialEq, QuickImpl)] enum Test<'a, 'b> { - #[quick_impl(pub(crate) const is, as_ref, pub as_ref_mut, pub(crate) from, pub(crate) into, impl From)] + #[quick_impl( + pub(crate) is, + as_ref, + pub as_ref_mut, + pub(crate) from, + pub(crate) into, + set, + pub try_into, + impl Default, + impl From, + impl TryInto + )] A(&'a usize, &'b mut isize), } diff --git a/tests/test_struct.rs b/tests/test_struct.rs index b5e7bf0..4ae1f32 100644 --- a/tests/test_struct.rs +++ b/tests/test_struct.rs @@ -6,7 +6,20 @@ use quick_impl::QuickImpl; fn test_struct_single_named() { #[derive(QuickImpl)] struct Test { - #[quick_impl(pub const get = "{}", pub get_clone, get_mut, const into, pub(crate) set, pub take, pub(crate) const with, impl Deref, impl DerefMut, impl Into, impl AsRef, impl AsMut)] + #[quick_impl( + pub const get = "{}", + pub get_clone, + get_mut, + const into, + pub(crate) set, + pub take, + pub(crate) const with, + impl Deref, + impl DerefMut, + impl Into, + impl AsRef, + impl AsMut, + )] a: usize, } @@ -33,8 +46,21 @@ fn test_struct_single_named() { fn test_struct_single_unnamed() { #[derive(QuickImpl)] struct Test( - #[quick_impl(pub const get, get_mut, const into, pub(crate) set, take, pub(crate) const with, impl Deref, impl DerefMut, impl Into, impl AsRef, impl AsMut)] - usize, + #[quick_impl( + pub const get, + pub get_clone = "get_clone_0", + get_mut, + const into, + pub(crate) set, + pub take, + pub(crate) const with, + impl Deref, + impl DerefMut, + impl Into, + impl AsRef, + impl AsMut, + )] + usize, ); let a = Test(12);