Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum messages: Make the returned values all 'static #160

Merged
merged 2 commits into from
May 18, 2021
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
6 changes: 3 additions & 3 deletions strum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions strum_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,23 +396,23 @@ 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"),
/// _ => None
/// }
/// }
///
/// 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"),
/// _ => None
/// }
/// }
///
/// fn get_serializations(&self) -> &[&str] {
/// fn get_serializations(&self) -> &'static [&'static str] {
/// match self {
/// &Color::Red => {
/// static ARR: [&'static str; 1] = ["Red"];
Expand Down
6 changes: 3 additions & 3 deletions strum_macros/src/macros/enum_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ pub fn enum_message_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {

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),*
}
Expand Down