Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions strum_macros/src/macros/enum_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) fn enum_count_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {

Ok(quote! {
// Implementation
#[automatically_derived]
impl #impl_generics #strum_module_path::EnumCount for #name #ty_generics #where_clause {
const COUNT: usize = #n;
}
Expand Down
3 changes: 3 additions & 0 deletions strum_macros/src/macros/enum_discriminants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let impl_from = quote! {
#[automatically_derived]
impl #impl_generics ::core::convert::From< #name #ty_generics > for #discriminants_name #where_clause {
#[inline]
fn from(val: #name #ty_generics) -> #discriminants_name {
Expand All @@ -158,6 +159,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
let (impl_generics, _, _) = generics.split_for_impl();

quote! {
#[automatically_derived]
impl #impl_generics ::core::convert::From< #enum_life #name #ty_generics > for #discriminants_name #where_clause {
#[inline]
fn from(val: #enum_life #name #ty_generics) -> #discriminants_name {
Expand All @@ -171,6 +173,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
let impl_into_discriminant = match type_properties.discriminant_vis {
// If the visibilty is unspecified or `pub` then we implement IntoDiscriminant
None | Some(syn::Visibility::Public(..)) => quote! {
#[automatically_derived]
impl #impl_generics #strum_module_path::IntoDiscriminant for #name #ty_generics #where_clause {
type Discriminant = #discriminants_name;

Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/enum_is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
.collect();

Ok(quote! {
#[automatically_derived]
impl #impl_generics #enum_name #ty_generics #where_clause {
#(#variants)*
}
Expand Down
8 changes: 8 additions & 0 deletions strum_macros/src/macros/enum_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
marker: ::core::marker::PhantomData #phantom_data,
}

#[automatically_derived]
impl #impl_generics ::core::fmt::Debug for #iter_name #ty_generics #where_clause {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
// We don't know if the variants implement debug themselves so the only thing we
Expand All @@ -90,6 +91,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
}

#[automatically_derived]
impl #impl_generics #iter_name #ty_generics #where_clause {
fn get(&self, idx: usize) -> ::core::option::Option<#name #ty_generics> {
match idx {
Expand All @@ -98,6 +100,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
}

#[automatically_derived]
impl #impl_generics #strum_module_path::IntoEnumIterator for #name #ty_generics #where_clause {
type Iterator = #iter_name #ty_generics;

Expand All @@ -111,6 +114,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
}

#[automatically_derived]
impl #impl_generics Iterator for #iter_name #ty_generics #where_clause {
type Item = #name #ty_generics;

Expand Down Expand Up @@ -141,13 +145,15 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
}

#[automatically_derived]
impl #impl_generics ExactSizeIterator for #iter_name #ty_generics #where_clause {
#[inline]
fn len(&self) -> usize {
self.size_hint().0
}
}

#[automatically_derived]
impl #impl_generics DoubleEndedIterator for #iter_name #ty_generics #where_clause {
#[inline]
fn next_back(&mut self) -> ::core::option::Option<<Self as Iterator>::Item> {
Expand All @@ -166,8 +172,10 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
}

#[automatically_derived]
impl #impl_generics ::core::iter::FusedIterator for #iter_name #ty_generics #where_clause { }

#[automatically_derived]
impl #impl_generics Clone for #iter_name #ty_generics #where_clause {
#[inline]
fn clone(&self) -> #iter_name #ty_generics {
Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/enum_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn enum_message_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}

Ok(quote! {
#[automatically_derived]
impl #impl_generics #strum_module_path::EnumMessage for #name #ty_generics #where_clause {
#[inline]
fn get_message(&self) -> ::core::option::Option<&'static str> {
Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/enum_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn enum_properties_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
);

Ok(quote! {
#[automatically_derived]
impl #impl_generics #strum_module_path::EnumProperty for #name #ty_generics #where_clause {
#[inline]
fn get_str(&self, prop: &str) -> ::core::option::Option<&'static str> {
Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/enum_try_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn enum_try_as_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
.collect();

Ok(quote! {
#[automatically_derived]
impl #impl_generics #enum_name #ty_generics #where_clause {
#(#variants)*
}
Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/from_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub fn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {

Ok(quote! {
#[allow(clippy::use_self)]
#[automatically_derived]
impl #impl_generics #name #ty_generics #where_clause {
#[doc = "Try to create [Self] from the raw representation"]
#[inline]
Expand Down
8 changes: 7 additions & 1 deletion strum_macros/src/macros/strings/as_ref_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn as_ref_str_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
})?;

Ok(quote! {
#[automatically_derived]
impl #impl_generics ::core::convert::AsRef<str> for #name #ty_generics #where_clause {
#[inline]
fn as_ref(&self) -> &str {
Expand Down Expand Up @@ -110,6 +111,7 @@ pub fn as_static_str_inner(

Ok(match trait_variant {
GenerateTraitVariant::AsStaticStr => quote! {
#[automatically_derived]
impl #impl_generics #strum_module_path::AsStaticRef<str> for #name #ty_generics #where_clause {
#[inline]
fn as_static(&self) -> &'static str {
Expand All @@ -120,6 +122,7 @@ pub fn as_static_str_inner(
}
},
GenerateTraitVariant::From if !type_properties.const_into_str => quote! {
#[automatically_derived]
impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
#[inline]
fn from(x: #name #ty_generics) -> &'static str {
Expand All @@ -128,6 +131,7 @@ pub fn as_static_str_inner(
}
}
}
#[automatically_derived]
impl #impl_generics2 ::core::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
#[inline]
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
Expand All @@ -138,21 +142,23 @@ pub fn as_static_str_inner(
}
},
GenerateTraitVariant::From => quote! {
#[automatically_derived]
impl #impl_generics #name #ty_generics #where_clause {
pub const fn into_str(&self) -> &'static str {
match self {
#(#arms),*
}
}
}

#[automatically_derived]
impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
fn from(x: #name #ty_generics) -> &'static str {
match x {
#(#arms),*
}
}
}
#[automatically_derived]
impl #impl_generics2 ::core::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
x.into_str()
Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/strings/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}

Ok(quote! {
#[automatically_derived]
impl #impl_generics ::core::fmt::Display for #name #ty_generics #where_clause {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::result::Result<(), ::core::fmt::Error> {
match *self {
Expand Down
2 changes: 2 additions & 0 deletions strum_macros/src/macros/strings/from_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub fn from_string_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {

let from_str = quote! {
#[allow(clippy::use_self)]
#[automatically_derived]
impl #impl_generics ::core::str::FromStr for #name #ty_generics #where_clause {
type Err = #default_err_ty;

Expand Down Expand Up @@ -216,6 +217,7 @@ fn try_from_str(
) -> TokenStream {
quote! {
#[allow(clippy::use_self)]
#[automatically_derived]
impl #impl_generics ::core::convert::TryFrom<&str> for #name #ty_generics #where_clause {
type Error = #default_err_ty;

Expand Down
1 change: 1 addition & 0 deletions strum_macros/src/macros/strings/to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn to_string_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {

Ok(quote! {
#[allow(clippy::use_self)]
#[automatically_derived]
impl #impl_generics ::std::string::ToString for #name #ty_generics #where_clause {
fn to_string(&self) -> ::std::string::String {
match *self {
Expand Down