diff --git a/core/src/from_meta.rs b/core/src/from_meta.rs index 9bcea00..048acb7 100644 --- a/core/src/from_meta.rs +++ b/core/src/from_meta.rs @@ -3,6 +3,10 @@ use std::cell::RefCell; use std::collections::hash_map::HashMap; use std::collections::HashSet; use std::hash::BuildHasher; +use std::num::{ + NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, + NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, +}; use std::rc::Rc; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -249,6 +253,18 @@ from_meta_num!(i32); from_meta_num!(i64); from_meta_num!(i128); from_meta_num!(isize); +from_meta_num!(NonZeroU8); +from_meta_num!(NonZeroU16); +from_meta_num!(NonZeroU32); +from_meta_num!(NonZeroU64); +from_meta_num!(NonZeroU128); +from_meta_num!(NonZeroUsize); +from_meta_num!(NonZeroI8); +from_meta_num!(NonZeroI16); +from_meta_num!(NonZeroI32); +from_meta_num!(NonZeroI64); +from_meta_num!(NonZeroI128); +from_meta_num!(NonZeroIsize); /// Generate an impl of `FromMeta` that will accept strings which parse to floats or /// float literals. @@ -781,6 +797,8 @@ hash_map!(syn::Path); /// it should not be considered by the parsing. #[cfg(test)] mod tests { + use std::num::{NonZeroU32, NonZeroU64}; + use proc_macro2::TokenStream; use quote::quote; use syn::parse_quote; @@ -853,6 +871,20 @@ mod tests { assert_eq!(fm::(quote!(ignore = "1.4e10")), 1.4e10); } + #[should_panic(expected = "UnknownValue(\"0\")")] + #[test] + fn nonzero_number_fails() { + fm::(quote!(ignore = "0")); + } + + #[test] + fn nonzero_number_succeeds() { + assert_eq!( + fm::(quote!(ignore = "2")), + NonZeroU32::new(2).unwrap() + ); + } + #[test] fn int_without_quotes() { assert_eq!(fm::(quote!(ignore = 2)), 2u8);