Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
edition = "2018"

Expand Down
11 changes: 3 additions & 8 deletions from-str/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<bool> {
/// match s.len() {
/// 2 => if s[0] == b'n' && s[1] == b'o' {
Expand All @@ -49,9 +47,6 @@ use proc_macro2::{Literal, Ident, TokenStream, Span};
///
/// None
/// }
/// # };
///
/// # assert_eq!(String::from_utf8(code).unwrap(), format!("{}", generated));
/// # }
/// ```
#[derive(Clone)]
Expand Down Expand Up @@ -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
}
});
Expand Down Expand Up @@ -201,7 +196,7 @@ impl<T> Forest<T>
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);));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ pub fn derive_try_from_repr(input: &syn::DeriveInput) -> Result<TokenStream, Err
.map(|(v, ctor)| quote!(const #v: #repr = #ctor as #repr));

Ok(quote! {
impl ::std::convert::TryFrom<#repr> for #name {
impl ::core::convert::TryFrom<#repr> for #name {
type Error = ();

#[allow(non_upper_case_globals)]
fn try_from(d: #repr) -> Result<Self, Self::Error> {
fn try_from(d: #repr) -> ::core::result::Result<Self, Self::Error> {

#( #const_defs; )*

match d {
#( #consts => Ok(#ctors), )*
_ => Err(())
#( #consts => ::core::result::Result::Ok(#ctors), )*
_ => ::core::result::Result::Err(())
}
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn derive_repr_from(input: &syn::DeriveInput) -> Result<TokenStream, ErrorLi
}

Ok(quote! {
impl ::std::convert::From<#name> for #repr {
impl ::core::convert::From<#name> for #repr {
fn from(d: #name) -> Self {
d as #repr
}
Expand Down
4 changes: 2 additions & 2 deletions src/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ pub fn derive(ast: &syn::DeriveInput) -> Result<TokenStream, ErrorList> {
}

Ok(quote!{
impl ::std::str::FromStr for #enum_name {
impl ::core::str::FromStr for #enum_name {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
fn from_str(s: &str) -> ::core::result::Result<Self, Self::Err> {
#trie
_parse(s.as_bytes()).ok_or(())
}
Expand Down
8 changes: 4 additions & 4 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand All @@ -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) })
}
},

Expand All @@ -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) })
}
},

Expand All @@ -130,7 +130,7 @@ impl IterImpl {

quote! {
impl #ty {
fn iter() -> impl Iterator<Item = #ty> + Clone {
fn iter() -> impl ::core::iter::Iterator<Item = #ty> + ::core::clone::Clone {
#body
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
16 changes: 0 additions & 16 deletions tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,3 @@ fn skip_c_like() {
assert_eq!(vec![A, C],
SkipCLike::iter().collect::<Vec<_>>());
}

#[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::<Vec<_>>());
}