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:
parent
1e3acb64a7
commit
a1464c5bc2
@ -1,12 +1,12 @@
|
||||
//! # Documentation for Additional Attributes
|
||||
//!
|
||||
//!
|
||||
//! ## Attributes on Enums
|
||||
//!
|
||||
//! 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:
|
||||
//!
|
||||
//!
|
||||
//! - `camelCase`
|
||||
//! - `PascalCase`
|
||||
//! - `kebab-case`
|
||||
@ -17,7 +17,7 @@
|
||||
//! - `UPPERCASE`
|
||||
//! - `title_case`
|
||||
//! - `mixed_case`
|
||||
//!
|
||||
//!
|
||||
//! ```rust
|
||||
//! use std::string::ToString;
|
||||
//! use strum;
|
||||
@ -50,7 +50,7 @@
|
||||
//!
|
||||
//! - 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.
|
||||
//!
|
||||
//!
|
||||
//! ## Attributes on Variants
|
||||
//!
|
||||
//! Custom attributes are applied to a variant by adding `#[strum(parameter="value")]` to the variant.
|
||||
|
@ -24,9 +24,7 @@
|
||||
//! ```
|
||||
//!
|
||||
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
|
||||
// only for documentation purposes
|
||||
@ -168,7 +166,10 @@ pub trait EnumProperty {
|
||||
|
||||
/// A cheap reference-to-reference conversion. Used to convert a value to a
|
||||
/// 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>
|
||||
where
|
||||
T: ?Sized,
|
||||
|
@ -192,7 +192,10 @@ pub fn variant_names(input: proc_macro::TokenStream) -> proc_macro::TokenStream
|
||||
}
|
||||
|
||||
#[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 {
|
||||
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;
|
||||
/// 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))]
|
||||
pub fn to_string(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
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));
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// On versions of rust >= 1.46, the `from_repr` function is marked `const`.
|
||||
///
|
||||
///
|
||||
/// ```rust
|
||||
/// use strum_macros::FromRepr;
|
||||
///
|
||||
///
|
||||
/// #[derive(FromRepr, Debug, PartialEq)]
|
||||
/// #[repr(u8)]
|
||||
/// enum Number {
|
||||
/// One = 1,
|
||||
/// Three = 3,
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// # #[rustversion::since(1.46)]
|
||||
/// const fn number_from_repr(d: u8) -> Option<Number> {
|
||||
/// 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 {
|
||||
let ast = syn::parse_macro_input!(input as DeriveInput);
|
||||
|
||||
let toks = macros::from_repr::from_repr_inner(&ast)
|
||||
.unwrap_or_else(|err| err.to_compile_error());
|
||||
let toks =
|
||||
macros::from_repr::from_repr_inner(&ast).unwrap_or_else(|err| err.to_compile_error());
|
||||
debug_print_generated(&ast, &toks);
|
||||
toks.into()
|
||||
}
|
||||
|
@ -103,8 +103,7 @@ pub fn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
||||
},
|
||||
};
|
||||
|
||||
constant_defs
|
||||
.push(quote! {const #const_var_ident: #discriminant_type = #const_val_expr;});
|
||||
constant_defs.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)});
|
||||
|
||||
prev_const_var_ident = Some(const_var_ident);
|
||||
|
@ -18,8 +18,7 @@ pub fn from_string_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
|
||||
let strum_module_path = type_properties.crate_module_path();
|
||||
|
||||
let mut default_kw = None;
|
||||
let mut default =
|
||||
quote! { _ => ::core::result::Result::Err(#strum_module_path::ParseError::VariantNotFound) };
|
||||
let mut default = quote! { _ => ::core::result::Result::Err(#strum_module_path::ParseError::VariantNotFound) };
|
||||
let mut arms = Vec::new();
|
||||
for variant in variants {
|
||||
let ident = &variant.ident;
|
||||
|
Loading…
Reference in New Issue
Block a user