mirror of
https://github.com/danog/strum.git
synced 2024-11-30 04:28:59 +01:00
Replaced ::std with ::core where applicable. (#145)
This makes these macros usable with `no_std` projects.
This commit is contained in:
parent
96ee0a9a30
commit
684f119dab
@ -99,7 +99,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_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
|
||||||
let impl_from = quote! {
|
let impl_from = quote! {
|
||||||
impl #impl_generics ::std::convert::From< #name #ty_generics > for #discriminants_name #where_clause {
|
impl #impl_generics ::core::convert::From< #name #ty_generics > for #discriminants_name #where_clause {
|
||||||
fn from(val: #name #ty_generics) -> #discriminants_name {
|
fn from(val: #name #ty_generics) -> #discriminants_name {
|
||||||
#from_fn_body
|
#from_fn_body
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
let (impl_generics, _, _) = generics.split_for_impl();
|
let (impl_generics, _, _) = generics.split_for_impl();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::std::convert::From< #enum_life #name #ty_generics > for #discriminants_name #where_clause {
|
impl #impl_generics ::core::convert::From< #enum_life #name #ty_generics > for #discriminants_name #where_clause {
|
||||||
fn from(val: #enum_life #name #ty_generics) -> #discriminants_name {
|
fn from(val: #enum_life #name #ty_generics) -> #discriminants_name {
|
||||||
#from_fn_body
|
#from_fn_body
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
let params = match &variant.fields {
|
let params = match &variant.fields {
|
||||||
Unit => quote! {},
|
Unit => quote! {},
|
||||||
Unnamed(fields) => {
|
Unnamed(fields) => {
|
||||||
let defaults = ::std::iter::repeat(quote!(::std::default::Default::default()))
|
let defaults = ::std::iter::repeat(quote!(::core::default::Default::default()))
|
||||||
.take(fields.unnamed.len());
|
.take(fields.unnamed.len());
|
||||||
quote! { (#(#defaults),*) }
|
quote! { (#(#defaults),*) }
|
||||||
}
|
}
|
||||||
@ -52,16 +52,16 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
.named
|
.named
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| field.ident.as_ref().unwrap());
|
.map(|field| field.ident.as_ref().unwrap());
|
||||||
quote! { {#(#fields: ::std::default::Default::default()),*} }
|
quote! { {#(#fields: ::core::default::Default::default()),*} }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
arms.push(quote! {#idx => ::std::option::Option::Some(#name::#ident #params)});
|
arms.push(quote! {#idx => ::core::option::Option::Some(#name::#ident #params)});
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let variant_count = arms.len();
|
let variant_count = arms.len();
|
||||||
arms.push(quote! { _ => ::std::option::Option::None });
|
arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
let iter_name = syn::parse_str::<Ident>(&format!("{}Iter", name)).unwrap();
|
let iter_name = syn::parse_str::<Ident>(&format!("{}Iter", name)).unwrap();
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
@ -69,7 +69,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
#vis struct #iter_name #ty_generics {
|
#vis struct #iter_name #ty_generics {
|
||||||
idx: usize,
|
idx: usize,
|
||||||
back_idx: usize,
|
back_idx: usize,
|
||||||
marker: ::std::marker::PhantomData #phantom_data,
|
marker: ::core::marker::PhantomData #phantom_data,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl #impl_generics #iter_name #ty_generics #where_clause {
|
impl #impl_generics #iter_name #ty_generics #where_clause {
|
||||||
@ -86,7 +86,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
#iter_name {
|
#iter_name {
|
||||||
idx: 0,
|
idx: 0,
|
||||||
back_idx: 0,
|
back_idx: 0,
|
||||||
marker: ::std::marker::PhantomData,
|
marker: ::core::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ pub fn enum_message_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
let params = params.clone();
|
let params = params.clone();
|
||||||
|
|
||||||
// Push the simple message.
|
// Push the simple message.
|
||||||
let tokens = quote! { &#name::#ident #params => ::std::option::Option::Some(#msg) };
|
let tokens = quote! { &#name::#ident #params => ::core::option::Option::Some(#msg) };
|
||||||
arms.push(tokens.clone());
|
arms.push(tokens.clone());
|
||||||
|
|
||||||
if detailed_messages.is_none() {
|
if detailed_messages.is_none() {
|
||||||
@ -66,27 +66,27 @@ pub fn enum_message_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
let params = params.clone();
|
let params = params.clone();
|
||||||
// Push the simple message.
|
// Push the simple message.
|
||||||
detailed_arms
|
detailed_arms
|
||||||
.push(quote! { &#name::#ident #params => ::std::option::Option::Some(#msg) });
|
.push(quote! { &#name::#ident #params => ::core::option::Option::Some(#msg) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if arms.len() < variants.len() {
|
if arms.len() < variants.len() {
|
||||||
arms.push(quote! { _ => ::std::option::Option::None });
|
arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
}
|
}
|
||||||
|
|
||||||
if detailed_arms.len() < variants.len() {
|
if detailed_arms.len() < variants.len() {
|
||||||
detailed_arms.push(quote! { _ => ::std::option::Option::None });
|
detailed_arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
impl #impl_generics ::strum::EnumMessage for #name #ty_generics #where_clause {
|
impl #impl_generics ::strum::EnumMessage for #name #ty_generics #where_clause {
|
||||||
fn get_message(&self) -> ::std::option::Option<&str> {
|
fn get_message(&self) -> ::core::option::Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
#(#arms),*
|
#(#arms),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_detailed_message(&self) -> ::std::option::Option<&str> {
|
fn get_detailed_message(&self) -> ::core::option::Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
#(#detailed_arms),*
|
#(#detailed_arms),*
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,12 @@ pub fn enum_properties_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (key, value) in variant_properties.string_props {
|
for (key, value) in variant_properties.string_props {
|
||||||
string_arms.push(quote! { #key => ::std::option::Option::Some( #value )})
|
string_arms.push(quote! { #key => ::core::option::Option::Some( #value )})
|
||||||
}
|
}
|
||||||
|
|
||||||
string_arms.push(quote! { _ => ::std::option::Option::None });
|
string_arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
bool_arms.push(quote! { _ => ::std::option::Option::None });
|
bool_arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
num_arms.push(quote! { _ => ::std::option::Option::None });
|
num_arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
|
|
||||||
arms.push(quote! {
|
arms.push(quote! {
|
||||||
&#name::#ident #params => {
|
&#name::#ident #params => {
|
||||||
@ -49,12 +49,12 @@ pub fn enum_properties_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if arms.len() < variants.len() {
|
if arms.len() < variants.len() {
|
||||||
arms.push(quote! { _ => ::std::option::Option::None });
|
arms.push(quote! { _ => ::core::option::Option::None });
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
impl #impl_generics ::strum::EnumProperty for #name #ty_generics #where_clause {
|
impl #impl_generics ::strum::EnumProperty for #name #ty_generics #where_clause {
|
||||||
fn get_str(&self, prop: &str) -> ::std::option::Option<&'static str> {
|
fn get_str(&self, prop: &str) -> ::core::option::Option<&'static str> {
|
||||||
match self {
|
match self {
|
||||||
#(#arms),*
|
#(#arms),*
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ pub fn as_ref_str_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
|
||||||
let arms = get_arms(ast)?;
|
let arms = get_arms(ast)?;
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
impl #impl_generics ::std::convert::AsRef<str> for #name #ty_generics #where_clause {
|
impl #impl_generics ::core::convert::AsRef<str> for #name #ty_generics #where_clause {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
#(#arms),*
|
#(#arms),*
|
||||||
@ -97,14 +97,14 @@ pub fn as_static_str_inner(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
GenerateTraitVariant::From => quote! {
|
GenerateTraitVariant::From => quote! {
|
||||||
impl #impl_generics ::std::convert::From<#name #ty_generics> for &'static str #where_clause {
|
impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
|
||||||
fn from(x: #name #ty_generics) -> &'static str {
|
fn from(x: #name #ty_generics) -> &'static str {
|
||||||
match x {
|
match x {
|
||||||
#(#arms2),*
|
#(#arms2),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl #impl_generics2 ::std::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
|
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 {
|
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
|
||||||
match *x {
|
match *x {
|
||||||
#(#arms3),*
|
#(#arms3),*
|
||||||
|
@ -40,8 +40,8 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
impl #impl_generics ::std::fmt::Display for #name #ty_generics #where_clause {
|
impl #impl_generics ::core::fmt::Display for #name #ty_generics #where_clause {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::result::Result<(), ::core::fmt::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
#(#arms),*
|
#(#arms),*
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user