1
0
mirror of https://github.com/danog/strum.git synced 2024-11-30 04:28:59 +01:00

Run rustfmt over the whole tree

This commit is contained in:
Peter Glotfelty 2021-11-19 16:10:52 -08:00
parent 1e3acb64a7
commit a1464c5bc2
5 changed files with 26 additions and 21 deletions

View File

@ -1,12 +1,12 @@
//! # Documentation for Additional Attributes //! # Documentation for Additional Attributes
//! //!
//! ## Attributes on Enums //! ## Attributes on Enums
//! //!
//! Strum supports several custom attributes to modify the generated code. At the enum level, the following attributes are supported: //! Strum supports several custom attributes to modify the generated code. At the enum level, the following attributes are supported:
//! //!
//! - `#[strum(serialize_all = "case_style")]` attribute can be used to change the case used when serializing to and deserializing //! - `#[strum(serialize_all = "case_style")]` attribute can be used to change the case used when serializing to and deserializing
//! from strings. This feature is enabled by [withoutboats/heck](https://github.com/withoutboats/heck) and supported case styles are: //! from strings. This feature is enabled by [withoutboats/heck](https://github.com/withoutboats/heck) and supported case styles are:
//! //!
//! - `camelCase` //! - `camelCase`
//! - `PascalCase` //! - `PascalCase`
//! - `kebab-case` //! - `kebab-case`
@ -17,7 +17,7 @@
//! - `UPPERCASE` //! - `UPPERCASE`
//! - `title_case` //! - `title_case`
//! - `mixed_case` //! - `mixed_case`
//! //!
//! ```rust //! ```rust
//! use std::string::ToString; //! use std::string::ToString;
//! use strum; //! use strum;
@ -50,7 +50,7 @@
//! //!
//! - You can also apply the `#[strum(ascii_case_insensitive)]` attribute to the enum, //! - You can also apply the `#[strum(ascii_case_insensitive)]` attribute to the enum,
//! and this has the same effect of applying it to every variant. //! and this has the same effect of applying it to every variant.
//! //!
//! ## Attributes on Variants //! ## Attributes on Variants
//! //!
//! Custom attributes are applied to a variant by adding `#[strum(parameter="value")]` to the variant. //! Custom attributes are applied to a variant by adding `#[strum(parameter="value")]` to the variant.

View File

@ -24,9 +24,7 @@
//! ``` //! ```
//! //!
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
// only for documentation purposes // only for documentation purposes
@ -168,7 +166,10 @@ pub trait EnumProperty {
/// A cheap reference-to-reference conversion. Used to convert a value to a /// A cheap reference-to-reference conversion. Used to convert a value to a
/// reference value with `'static` lifetime within generic code. /// reference value with `'static` lifetime within generic code.
#[deprecated(since="0.22.0", note="please use `#[derive(IntoStaticStr)]` instead")] #[deprecated(
since = "0.22.0",
note = "please use `#[derive(IntoStaticStr)]` instead"
)]
pub trait AsStaticRef<T> pub trait AsStaticRef<T>
where where
T: ?Sized, T: ?Sized,

View File

@ -192,7 +192,10 @@ pub fn variant_names(input: proc_macro::TokenStream) -> proc_macro::TokenStream
} }
#[proc_macro_derive(AsStaticStr, attributes(strum))] #[proc_macro_derive(AsStaticStr, attributes(strum))]
#[deprecated(since="0.22.0", note="please use `#[derive(IntoStaticStr)]` instead")] #[deprecated(
since = "0.22.0",
note = "please use `#[derive(IntoStaticStr)]` instead"
)]
pub fn as_static_str(input: proc_macro::TokenStream) -> proc_macro::TokenStream { pub fn as_static_str(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ast = syn::parse_macro_input!(input as DeriveInput); let ast = syn::parse_macro_input!(input as DeriveInput);
@ -272,7 +275,10 @@ pub fn into_static_str(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
/// let yellow = Color::Yellow; /// let yellow = Color::Yellow;
/// assert_eq!(String::from("Yellow"), yellow.to_string()); /// assert_eq!(String::from("Yellow"), yellow.to_string());
/// ``` /// ```
#[deprecated(since="0.22.0", note="please use `#[derive(Display)]` instead. See issue https://github.com/Peternator7/strum/issues/132")] #[deprecated(
since = "0.22.0",
note = "please use `#[derive(Display)]` instead. See issue https://github.com/Peternator7/strum/issues/132"
)]
#[proc_macro_derive(ToString, attributes(strum))] #[proc_macro_derive(ToString, attributes(strum))]
pub fn to_string(input: proc_macro::TokenStream) -> proc_macro::TokenStream { pub fn to_string(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ast = syn::parse_macro_input!(input as DeriveInput); let ast = syn::parse_macro_input!(input as DeriveInput);
@ -421,19 +427,19 @@ pub fn enum_iter(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/// ///
/// assert_eq!(None, Vehicle::from_repr(0)); /// assert_eq!(None, Vehicle::from_repr(0));
/// ``` /// ```
/// ///
/// On versions of rust >= 1.46, the `from_repr` function is marked `const`. /// On versions of rust >= 1.46, the `from_repr` function is marked `const`.
/// ///
/// ```rust /// ```rust
/// use strum_macros::FromRepr; /// use strum_macros::FromRepr;
/// ///
/// #[derive(FromRepr, Debug, PartialEq)] /// #[derive(FromRepr, Debug, PartialEq)]
/// #[repr(u8)] /// #[repr(u8)]
/// enum Number { /// enum Number {
/// One = 1, /// One = 1,
/// Three = 3, /// Three = 3,
/// } /// }
/// ///
/// # #[rustversion::since(1.46)] /// # #[rustversion::since(1.46)]
/// const fn number_from_repr(d: u8) -> Option<Number> { /// const fn number_from_repr(d: u8) -> Option<Number> {
/// Number::from_repr(d) /// Number::from_repr(d)
@ -454,8 +460,8 @@ pub fn enum_iter(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
pub fn from_repr(input: proc_macro::TokenStream) -> proc_macro::TokenStream { pub fn from_repr(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ast = syn::parse_macro_input!(input as DeriveInput); let ast = syn::parse_macro_input!(input as DeriveInput);
let toks = macros::from_repr::from_repr_inner(&ast) let toks =
.unwrap_or_else(|err| err.to_compile_error()); macros::from_repr::from_repr_inner(&ast).unwrap_or_else(|err| err.to_compile_error());
debug_print_generated(&ast, &toks); debug_print_generated(&ast, &toks);
toks.into() toks.into()
} }

View File

@ -103,8 +103,7 @@ pub fn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}, },
}; };
constant_defs constant_defs.push(quote! {const #const_var_ident: #discriminant_type = #const_val_expr;});
.push(quote! {const #const_var_ident: #discriminant_type = #const_val_expr;});
arms.push(quote! {v if v == #const_var_ident => ::core::option::Option::Some(#name::#ident #params)}); arms.push(quote! {v if v == #const_var_ident => ::core::option::Option::Some(#name::#ident #params)});
prev_const_var_ident = Some(const_var_ident); prev_const_var_ident = Some(const_var_ident);

View File

@ -18,8 +18,7 @@ pub fn from_string_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
let strum_module_path = type_properties.crate_module_path(); let strum_module_path = type_properties.crate_module_path();
let mut default_kw = None; let mut default_kw = None;
let mut default = let mut default = quote! { _ => ::core::result::Result::Err(#strum_module_path::ParseError::VariantNotFound) };
quote! { _ => ::core::result::Result::Err(#strum_module_path::ParseError::VariantNotFound) };
let mut arms = Vec::new(); let mut arms = Vec::new();
for variant in variants { for variant in variants {
let ident = &variant.ident; let ident = &variant.ident;