diff --git a/README.md b/README.md index ad254c6..b214c9d 100644 --- a/README.md +++ b/README.md @@ -23,18 +23,6 @@ strum = "0.19" strum_macros = "0.19" ``` -And add these lines to the root of your project, either lib.rs or main.rs. - -```rust -// Strum contains all the trait definitions -extern crate strum; -#[macro_use] -extern crate strum_macros; - -// Instead of #[macro_use], newer versions of rust should prefer -use strum_macros::{Display, EnumIter}; // etc. -``` - # Strum Macros Strum has implemented the following macros: diff --git a/strum/Cargo.toml b/strum/Cargo.toml index 9d0d538..25a5b20 100644 --- a/strum/Cargo.toml +++ b/strum/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "strum" version = "0.19.2" +edition = "2018" authors = ["Peter Glotfelty "] license = "MIT" diff --git a/strum/src/lib.rs b/strum/src/lib.rs index 0f00094..896ef9c 100644 --- a/strum/src/lib.rs +++ b/strum/src/lib.rs @@ -20,16 +20,6 @@ //! strum_macros = "0.18.0" //! ``` //! -//! And add these lines to the root of your project, either lib.rs or main.rs. -//! -//! ```rust -//! // Strum contains all the trait definitions -//! extern crate strum; -//! #[macro_use] -//! extern crate strum_macros; -//! # fn main() {} -//! ``` -//! //! # Strum Macros //! //! Strum has implemented the following macros: @@ -92,18 +82,16 @@ impl std::error::Error for ParseError { /// # Example /// /// ```rust -/// # extern crate strum; -/// # #[macro_use] extern crate strum_macros; /// # use std::fmt::Debug; /// // You need to bring the type into scope to use it!!! -/// use strum::IntoEnumIterator; +/// use strum::{EnumIter, IntoEnumIterator}; /// -/// #[derive(EnumIter,Debug)] +/// #[derive(EnumIter, Debug)] /// enum Color { -/// Red, -/// Green { range:usize }, -/// Blue(usize), -/// Yellow, +/// Red, +/// Green { range: usize }, +/// Blue(usize), +/// Yellow, /// } /// /// // Iterate over the items in an enum and perform some function on them. @@ -117,9 +105,7 @@ impl std::error::Error for ParseError { /// } /// } /// -/// fn main() { -/// generic_iterator::(|color| println!("{:?}", color)); -/// } +/// generic_iterator::(|color| println!("{:?}", color)); /// ``` pub trait IntoEnumIterator: Sized { type Iterator: Iterator; @@ -134,8 +120,6 @@ pub trait IntoEnumIterator: Sized { /// # Example /// /// ```rust -/// # extern crate strum; -/// # #[macro_use] extern crate strum_macros; /// # use std::fmt::Debug; /// // You need to bring the type into scope to use it!!! /// use strum::EnumMessage; @@ -149,10 +133,8 @@ pub trait IntoEnumIterator: Sized { /// Cat, /// } /// -/// fn main() { -/// let my_pet = Pet::Dog; -/// assert_eq!("I have a dog", my_pet.get_message().unwrap()); -/// } +/// let my_pet = Pet::Dog; +/// assert_eq!("I have a dog", my_pet.get_message().unwrap()); /// ``` pub trait EnumMessage { fn get_message(&self) -> Option<&str>; @@ -169,8 +151,6 @@ pub trait EnumMessage { /// # Example /// /// ```rust -/// # extern crate strum; -/// # #[macro_use] extern crate strum_macros; /// # use std::fmt::Debug; /// // You need to bring the type into scope to use it!!! /// use strum::EnumProperty; @@ -186,10 +166,8 @@ pub trait EnumMessage { /// Science, /// } /// -/// fn main() { -/// let history = Class::History; -/// assert_eq!("Ms.Frizzle", history.get_str("Teacher").unwrap()); -/// } +/// let history = Class::History; +/// assert_eq!("Ms.Frizzle", history.get_str("Teacher").unwrap()); /// ``` pub trait EnumProperty { fn get_str(&self, prop: &str) -> Option<&'static str>; @@ -225,11 +203,6 @@ pub trait VariantNames { const VARIANTS: &'static [&'static str]; } -#[cfg(feature = "derive")] -#[allow(unused_imports)] -#[macro_use] -extern crate strum_macros; - #[cfg(feature = "derive")] #[doc(hidden)] pub use strum_macros::*; diff --git a/strum_macros/Cargo.toml b/strum_macros/Cargo.toml index 98140f3..4e72157 100644 --- a/strum_macros/Cargo.toml +++ b/strum_macros/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "strum_macros" version = "0.19.2" +edition = "2018" authors = ["Peter Glotfelty "] license = "MIT" @@ -35,4 +36,4 @@ verbose-enumiter-name = [] verbose-enummessage-name = [] verbose-enumproperty-name = [] verbose-enumdiscriminants-name = [] -verbose-enumcount-name = [] \ No newline at end of file +verbose-enumcount-name = [] diff --git a/strum_macros/src/lib.rs b/strum_macros/src/lib.rs index 1b85ef7..57d8f18 100644 --- a/strum_macros/src/lib.rs +++ b/strum_macros/src/lib.rs @@ -9,13 +9,7 @@ #![recursion_limit = "128"] -extern crate heck; -#[macro_use] -extern crate syn; -#[macro_use] -extern crate quote; extern crate proc_macro; -extern crate proc_macro2; mod helpers; mod macros; diff --git a/strum_macros/src/macros/enum_count.rs b/strum_macros/src/macros/enum_count.rs index 0a26b62..aa510b4 100644 --- a/strum_macros/src/macros/enum_count.rs +++ b/strum_macros/src/macros/enum_count.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; pub(crate) fn enum_count_inner(ast: &syn::DeriveInput) -> TokenStream { let n = match ast.data { diff --git a/strum_macros/src/macros/enum_discriminants.rs b/strum_macros/src/macros/enum_discriminants.rs index c270329..ffa594f 100644 --- a/strum_macros/src/macros/enum_discriminants.rs +++ b/strum_macros/src/macros/enum_discriminants.rs @@ -1,5 +1,6 @@ use proc_macro2::{Span, TokenStream}; -use syn; +use quote::quote; +use syn::parse_quote; use crate::helpers::HasTypeProperties; diff --git a/strum_macros/src/macros/enum_iter.rs b/strum_macros/src/macros/enum_iter.rs index 1c8b5df..3a99482 100644 --- a/strum_macros/src/macros/enum_iter.rs +++ b/strum_macros/src/macros/enum_iter.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::HasStrumVariantProperties; diff --git a/strum_macros/src/macros/enum_messages.rs b/strum_macros/src/macros/enum_messages.rs index 62c799d..473c475 100644 --- a/strum_macros/src/macros/enum_messages.rs +++ b/strum_macros/src/macros/enum_messages.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::{HasStrumVariantProperties, HasTypeProperties}; diff --git a/strum_macros/src/macros/enum_properties.rs b/strum_macros/src/macros/enum_properties.rs index 469aafa..7b93b49 100644 --- a/strum_macros/src/macros/enum_properties.rs +++ b/strum_macros/src/macros/enum_properties.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::HasStrumVariantProperties; diff --git a/strum_macros/src/macros/enum_variant_names.rs b/strum_macros/src/macros/enum_variant_names.rs index 8e0f67a..a9e0209 100644 --- a/strum_macros/src/macros/enum_variant_names.rs +++ b/strum_macros/src/macros/enum_variant_names.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::{HasStrumVariantProperties, HasTypeProperties}; diff --git a/strum_macros/src/macros/strings/as_ref_str.rs b/strum_macros/src/macros/strings/as_ref_str.rs index 7ecfc6e..12fc3fc 100644 --- a/strum_macros/src/macros/strings/as_ref_str.rs +++ b/strum_macros/src/macros/strings/as_ref_str.rs @@ -1,5 +1,6 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; +use syn::parse_quote; use crate::helpers::{HasStrumVariantProperties, HasTypeProperties}; diff --git a/strum_macros/src/macros/strings/display.rs b/strum_macros/src/macros/strings/display.rs index fb62897..f328011 100644 --- a/strum_macros/src/macros/strings/display.rs +++ b/strum_macros/src/macros/strings/display.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::{HasStrumVariantProperties, HasTypeProperties}; diff --git a/strum_macros/src/macros/strings/from_string.rs b/strum_macros/src/macros/strings/from_string.rs index 6f97e39..7193b73 100644 --- a/strum_macros/src/macros/strings/from_string.rs +++ b/strum_macros/src/macros/strings/from_string.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::{HasStrumVariantProperties, HasTypeProperties}; diff --git a/strum_macros/src/macros/strings/to_string.rs b/strum_macros/src/macros/strings/to_string.rs index 234742f..b6f3b47 100644 --- a/strum_macros/src/macros/strings/to_string.rs +++ b/strum_macros/src/macros/strings/to_string.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use syn; +use quote::quote; use crate::helpers::{HasStrumVariantProperties, HasTypeProperties}; diff --git a/strum_tests/Cargo.toml b/strum_tests/Cargo.toml index 66c9f55..552f25d 100644 --- a/strum_tests/Cargo.toml +++ b/strum_tests/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "strum_tests" version = "0.19.0" +edition = "2018" authors = ["Peter Glotfelty "] [dependencies] diff --git a/strum_tests/src/lib.rs b/strum_tests/src/lib.rs index b1091c4..d840582 100644 --- a/strum_tests/src/lib.rs +++ b/strum_tests/src/lib.rs @@ -1,7 +1,4 @@ #![allow(unused_imports)] -extern crate strum; -#[macro_use] -extern crate strum_macros; use strum::*; #[allow(dead_code)] diff --git a/strum_tests/src/main.rs b/strum_tests/src/main.rs index 5c26718..b9c6284 100644 --- a/strum_tests/src/main.rs +++ b/strum_tests/src/main.rs @@ -1,6 +1,4 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; +use strum::{EnumCount, EnumDiscriminants, EnumString, ToString}; #[allow(dead_code)] #[derive(Debug, Eq, PartialEq, EnumString, ToString, EnumCount, EnumDiscriminants)] diff --git a/strum_tests/tests/as_ref_no_strum.rs b/strum_tests/tests/as_ref_no_strum.rs index 2606a33..82e3adc 100644 --- a/strum_tests/tests/as_ref_no_strum.rs +++ b/strum_tests/tests/as_ref_no_strum.rs @@ -1,5 +1,4 @@ -#[macro_use] -extern crate strum_macros; +use strum_macros::AsRefStr; #[derive(Debug, Eq, PartialEq, AsRefStr)] enum Color { diff --git a/strum_tests/tests/as_ref_str.rs b/strum_tests/tests/as_ref_str.rs index 33b2f25..8585862 100644 --- a/strum_tests/tests/as_ref_str.rs +++ b/strum_tests/tests/as_ref_str.rs @@ -1,9 +1,5 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; - use std::str::FromStr; -use strum::AsStaticRef; +use strum::{AsRefStr, AsStaticRef, AsStaticStr, EnumString, IntoStaticStr}; #[derive(Debug, Eq, PartialEq, EnumString, AsRefStr, AsStaticStr, IntoStaticStr)] enum Color { diff --git a/strum_tests/tests/display.rs b/strum_tests/tests/display.rs index 59d458a..2b20a56 100644 --- a/strum_tests/tests/display.rs +++ b/strum_tests/tests/display.rs @@ -1,6 +1,4 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; +use strum::{Display, EnumString}; #[derive(Debug, Eq, PartialEq, EnumString, Display)] enum Color { diff --git a/strum_tests/tests/enum_count.rs b/strum_tests/tests/enum_count.rs index 895fab6..4f03de0 100644 --- a/strum_tests/tests/enum_count.rs +++ b/strum_tests/tests/enum_count.rs @@ -1,8 +1,4 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; - -use strum::{EnumCount, IntoEnumIterator}; +use strum::{EnumCount, EnumIter, IntoEnumIterator}; #[derive(Debug, EnumCount, EnumIter)] enum Week { diff --git a/strum_tests/tests/enum_discriminants.rs b/strum_tests/tests/enum_discriminants.rs index 43a1637..04af86b 100644 --- a/strum_tests/tests/enum_discriminants.rs +++ b/strum_tests/tests/enum_discriminants.rs @@ -1,10 +1,5 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; -#[macro_use] -extern crate enum_variant_type; - -use strum::IntoEnumIterator; +use enum_variant_type::EnumVariantType; +use strum::{Display, EnumDiscriminants, EnumIter, EnumString, IntoEnumIterator}; #[allow(dead_code)] #[derive(Debug, Eq, PartialEq, EnumDiscriminants)] diff --git a/strum_tests/tests/enum_iter.rs b/strum_tests/tests/enum_iter.rs index a2174b5..35ec9eb 100644 --- a/strum_tests/tests/enum_iter.rs +++ b/strum_tests/tests/enum_iter.rs @@ -1,8 +1,4 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; - -use strum::IntoEnumIterator; +use strum::{EnumIter, IntoEnumIterator}; #[derive(Debug, Eq, PartialEq, EnumIter)] enum Week { diff --git a/strum_tests/tests/enum_message.rs b/strum_tests/tests/enum_message.rs index 5d506a4..1d3de33 100644 --- a/strum_tests/tests/enum_message.rs +++ b/strum_tests/tests/enum_message.rs @@ -1,8 +1,3 @@ -#![allow(unused_imports)] -extern crate strum; -#[macro_use] -extern crate strum_macros; - use strum::EnumMessage; #[derive(Debug, Eq, PartialEq, EnumMessage)] diff --git a/strum_tests/tests/enum_props.rs b/strum_tests/tests/enum_props.rs index b9b9fc2..55be0f6 100644 --- a/strum_tests/tests/enum_props.rs +++ b/strum_tests/tests/enum_props.rs @@ -1,8 +1,3 @@ -#![allow(unused_imports)] -extern crate strum; -#[macro_use] -extern crate strum_macros; - use strum::EnumProperty; #[derive(Debug, EnumProperty)] diff --git a/strum_tests/tests/enum_variant_names.rs b/strum_tests/tests/enum_variant_names.rs index 380e053..f9c8889 100644 --- a/strum_tests/tests/enum_variant_names.rs +++ b/strum_tests/tests/enum_variant_names.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate strum_macros; -#[macro_use] -extern crate structopt; -extern crate strum; -use strum::VariantNames; +use structopt::StructOpt; +use strum::{EnumString, EnumVariantNames, VariantNames}; #[test] fn simple() { diff --git a/strum_tests/tests/from_str.rs b/strum_tests/tests/from_str.rs index 88a8c3b..0c5782b 100644 --- a/strum_tests/tests/from_str.rs +++ b/strum_tests/tests/from_str.rs @@ -1,8 +1,5 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; - use std::str::FromStr; +use strum::EnumString; #[derive(Debug, Eq, PartialEq, EnumString)] enum Color { diff --git a/strum_tests/tests/serialize_all.rs b/strum_tests/tests/serialize_all.rs index c951a93..beec5fd 100644 --- a/strum_tests/tests/serialize_all.rs +++ b/strum_tests/tests/serialize_all.rs @@ -1,10 +1,7 @@ /// test serialize_all cooperation with other macroses -extern crate strum; -#[macro_use] -extern crate strum_macros; - use std::str::FromStr; use std::string::ToString; +use strum::{EnumString, IntoStaticStr, ToString}; #[derive(Debug, Eq, PartialEq, EnumString, ToString, IntoStaticStr)] #[strum(serialize_all = "title_case")] diff --git a/strum_tests/tests/to_string.rs b/strum_tests/tests/to_string.rs index 1ec5cfb..0f4c576 100644 --- a/strum_tests/tests/to_string.rs +++ b/strum_tests/tests/to_string.rs @@ -1,9 +1,6 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; - use std::str::FromStr; use std::string::ToString; +use strum::{EnumString, ToString}; #[derive(Debug, Eq, PartialEq, EnumString, ToString)] enum Color { diff --git a/strum_tests_rename/Cargo.toml b/strum_tests_rename/Cargo.toml index 10fcdc8..dc5d347 100644 --- a/strum_tests_rename/Cargo.toml +++ b/strum_tests_rename/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "strum_tests_rename" version = "0.19.0" +edition = "2018" authors = ["Peter Glotfelty "] [dependencies] @@ -20,4 +21,4 @@ features = [ "verbose-enummessage-name", "verbose-enumproperty-name", "verbose-enumdiscriminants-name" -] \ No newline at end of file +] diff --git a/strum_tests_rename/tests/color.rs b/strum_tests_rename/tests/color.rs index 3984058..0db926c 100644 --- a/strum_tests_rename/tests/color.rs +++ b/strum_tests_rename/tests/color.rs @@ -1,8 +1,7 @@ -extern crate strum; -#[macro_use] -extern crate strum_macros; +use strum::*; -#[derive(StrumEnumString, +#[derive( + StrumEnumString, StrumAsRefStr, StrumAsStaticStr, StrumIntoStaticStr, @@ -11,7 +10,8 @@ extern crate strum_macros; StrumEnumMessage, StrumEnumProperty, StrumEnumDiscriminants, - StrumEnumCount)] + StrumEnumCount, +)] pub enum Color { Red, Blue, @@ -23,5 +23,5 @@ pub enum Color { pub enum Color2 { Red, Blue, - Green -} \ No newline at end of file + Green, +}