diff --git a/strum/src/lib.rs b/strum/src/lib.rs index 755da759..ef273e23 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -118,9 +118,9 @@ pub trait IntoEnumIterator: Sized { /// assert_eq!("I have a dog", my_pet.get_message().unwrap()); /// ``` pub trait EnumMessage { - fn get_message(&self) -> Option<&str>; - fn get_detailed_message(&self) -> Option<&str>; - fn get_serializations(&self) -> &[&str]; + fn get_message(&self) -> Option<&'static str>; + fn get_detailed_message(&self) -> Option<&'static str>; + fn get_serializations(&self) -> &'static [&'static str]; } /// EnumProperty is a trait that makes it possible to store additional information diff --git a/strum_macros/src/lib.rs b/strum_macros/src/lib.rs index df06a5d8..269d5539 100644 --- a/strum_macros/src/lib.rs +++ b/strum_macros/src/lib.rs @@ -396,7 +396,7 @@ pub fn enum_iter(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// // Generated code looks like more or less like this: /// /* /// impl ::strum::EnumMessage for Color { -/// fn get_message(&self) -> ::std::option::Option<&str> { +/// fn get_message(&self) -> ::std::option::Option<&'static str> { /// match self { /// &Color::Red => ::std::option::Option::Some("Red"), /// &Color::Green {..} => ::std::option::Option::Some("Simply Green"), @@ -404,7 +404,7 @@ pub fn enum_iter(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// } /// } /// -/// fn get_detailed_message(&self) -> ::std::option::Option<&str> { +/// fn get_detailed_message(&self) -> ::std::option::Option<&'static str> { /// match self { /// &Color::Red => ::std::option::Option::Some("This is very red"), /// &Color::Green {..}=> ::std::option::Option::Some("Simply Green"), @@ -412,7 +412,7 @@ pub fn enum_iter(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// } /// } /// -/// fn get_serializations(&self) -> &[&str] { +/// fn get_serializations(&self) -> &'static [&'static str] { /// match self { /// &Color::Red => { /// static ARR: [&'static str; 1] = ["Red"]; diff --git a/strum_macros/src/macros/enum_messages.rs b/strum_macros/src/macros/enum_messages.rs index 58839233..19ff75cf 100644 --- a/strum_macros/src/macros/enum_messages.rs +++ b/strum_macros/src/macros/enum_messages.rs @@ -80,19 +80,19 @@ pub fn enum_message_inner(ast: &DeriveInput) -> syn::Result { Ok(quote! { impl #impl_generics ::strum::EnumMessage for #name #ty_generics #where_clause { - fn get_message(&self) -> ::core::option::Option<&str> { + fn get_message(&self) -> ::core::option::Option<&'static str> { match self { #(#arms),* } } - fn get_detailed_message(&self) -> ::core::option::Option<&str> { + fn get_detailed_message(&self) -> ::core::option::Option<&'static str> { match self { #(#detailed_arms),* } } - fn get_serializations(&self) -> &[&str] { + fn get_serializations(&self) -> &'static [&'static str] { match self { #(#serializations),* }