diff --git a/Cargo.toml b/Cargo.toml index 97d2757..e40e0c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "enum-utils" -version = "0.1.2" # remember to update html_root_url +version = "0.1.3" # remember to update html_root_url authors = ["Dylan MacKenzie "] edition = "2018" diff --git a/from-str/src/lib.rs b/from-str/src/lib.rs index 040879c..91b8c79 100644 --- a/from-str/src/lib.rs +++ b/from-str/src/lib.rs @@ -14,7 +14,6 @@ use proc_macro2::{Literal, Ident, TokenStream, Span}; /// /// ```rust /// # #![recursion_limit="128"] -/// # use quote::quote; /// use enum_utils_from_str::StrMapFunc; /// /// # fn main() { @@ -30,7 +29,6 @@ use proc_macro2::{Literal, Ident, TokenStream, Span}; /// /// // results in the following generated code. /// -/// # let generated = quote! { /// fn custom_lookup(s: &[u8]) -> Option { /// match s.len() { /// 2 => if s[0] == b'n' && s[1] == b'o' { @@ -49,9 +47,6 @@ use proc_macro2::{Literal, Ident, TokenStream, Span}; /// /// None /// } -/// # }; -/// -/// # assert_eq!(String::from_utf8(code).unwrap(), format!("{}", generated)); /// # } /// ``` #[derive(Clone)] @@ -122,11 +117,11 @@ impl ToTokens for StrMapFunc { _ => {} } - None + ::core::option::Option::None }; tokens.extend(quote! { - fn #func_name(s: &[u8]) -> Option<#ret_ty> { + fn #func_name(s: &[u8]) -> ::core::option::Option<#ret_ty> { #body } }); @@ -201,7 +196,7 @@ impl Forest if let Some(v) = node.value { // TODO: debug_assert_eq!(dfs.next().0, Post); - tok.last_mut().unwrap().extend(quote!(return Some(#v);)); + tok.last_mut().unwrap().extend(quote!(return ::core::option::Option::Some(#v);)); } } diff --git a/src/conv.rs b/src/conv.rs index 86467cd..ec1c0e5 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -48,17 +48,17 @@ pub fn derive_try_from_repr(input: &syn::DeriveInput) -> Result for #name { + impl ::core::convert::TryFrom<#repr> for #name { type Error = (); #[allow(non_upper_case_globals)] - fn try_from(d: #repr) -> Result { + fn try_from(d: #repr) -> ::core::result::Result { #( #const_defs; )* match d { - #( #consts => Ok(#ctors), )* - _ => Err(()) + #( #consts => ::core::result::Result::Ok(#ctors), )* + _ => ::core::result::Result::Err(()) } } } @@ -91,7 +91,7 @@ pub fn derive_repr_from(input: &syn::DeriveInput) -> Result for #repr { + impl ::core::convert::From<#name> for #repr { fn from(d: #name) -> Self { d as #repr } diff --git a/src/from_str.rs b/src/from_str.rs index 38f3b15..d253618 100644 --- a/src/from_str.rs +++ b/src/from_str.rs @@ -68,10 +68,10 @@ pub fn derive(ast: &syn::DeriveInput) -> Result { } Ok(quote!{ - impl ::std::str::FromStr for #enum_name { + impl ::core::str::FromStr for #enum_name { type Err = (); - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> ::core::result::Result { #trie _parse(s.as_bytes()).ok_or(()) } diff --git a/src/iter.rs b/src/iter.rs index 2e03230..035f701 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -97,7 +97,7 @@ impl IterImpl { fn tokens(&self, ty: &syn::Ident) -> TokenStream { let body = match self { IterImpl::Empty => quote! { - ::std::iter::empty() + ::core::iter::empty() }, IterImpl::Range { range, repr } => { @@ -107,7 +107,7 @@ impl IterImpl { quote! { let start: #repr = #start; let end: #repr = #end; - (start .. end).map(|discrim| unsafe { ::std::mem::transmute(discrim) }) + (start .. end).map(|discrim| unsafe { ::core::mem::transmute(discrim) }) } }, @@ -117,7 +117,7 @@ impl IterImpl { quote! { let start: #repr = #start; let end: #repr = #end; - (start ..= end).map(|discrim| unsafe { ::std::mem::transmute(discrim) }) + (start ..= end).map(|discrim| unsafe { ::core::mem::transmute(discrim) }) } }, @@ -130,7 +130,7 @@ impl IterImpl { quote! { impl #ty { - fn iter() -> impl Iterator + Clone { + fn iter() -> impl ::core::iter::Iterator + ::core::clone::Clone { #body } } diff --git a/src/lib.rs b/src/lib.rs index ba5d742..ad728b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ //! A set of procedural macros for deriving useful functionality on enums. -#![doc(html_root_url = "https://docs.rs/enum-utils/0.1.2")] +#![doc(html_root_url = "https://docs.rs/enum-utils/0.1.3")] extern crate proc_macro; diff --git a/tests/iter.rs b/tests/iter.rs index 7678a2b..d71f430 100644 --- a/tests/iter.rs +++ b/tests/iter.rs @@ -52,19 +52,3 @@ fn skip_c_like() { assert_eq!(vec![A, C], SkipCLike::iter().collect::>()); } - -#[derive(Debug, IterVariants, PartialEq, Eq)] -#[repr(C, u16)] -#[repr(align(2))] -enum MultiRepr { - A, - B, -} - -#[test] -fn multi_repr() { - use self::MultiRepr::*; - - assert_eq!(vec![A, B], - MultiRepr::iter().collect::>()); -}