1 use core::num::NonZeroU32;
2 use core::option::Option;
3 use core::option::Option::{Some, None};
7 fn test_create_nonzero_instance() {
9 NonZeroU32::new_unchecked(21)
14 fn test_size_nonzero_in_option() {
15 assert_eq!(size_of::<NonZeroU32>(), size_of::<Option<NonZeroU32>>());
19 fn test_match_on_nonzero_option() {
21 NonZeroU32::new_unchecked(42)
24 Some(val) => assert_eq!(val.get(), 42),
25 None => panic!("unexpected None while matching on Some(NonZeroU32(_))")
28 match unsafe { Some(NonZeroU32::new_unchecked(43)) } {
29 Some(val) => assert_eq!(val.get(), 43),
30 None => panic!("unexpected None while matching on Some(NonZeroU32(_))")
35 fn test_match_option_empty_vec() {
36 let a: Option<Vec<isize>> = Some(vec![]);
38 None => panic!("unexpected None while matching on Some(vec![])"),
44 fn test_match_option_vec() {
45 let a = Some(vec![1, 2, 3, 4]);
47 Some(v) => assert_eq!(v, [1, 2, 3, 4]),
48 None => panic!("unexpected None while matching on Some(vec![1, 2, 3, 4])")
53 fn test_match_option_rc() {
56 let five = Rc::new(5);
58 Some(r) => assert_eq!(*r, 5),
59 None => panic!("unexpected None while matching on Some(Rc::new(5))")
64 fn test_match_option_arc() {
67 let five = Arc::new(5);
69 Some(a) => assert_eq!(*a, 5),
70 None => panic!("unexpected None while matching on Some(Arc::new(5))")
75 fn test_match_option_empty_string() {
76 let a = Some(String::new());
78 None => panic!("unexpected None while matching on Some(String::new())"),
84 fn test_match_option_string() {
85 let five = "Five".to_string();
87 Some(s) => assert_eq!(s, "Five"),
88 None => panic!("unexpected None while matching on Some(String { ... })")
93 use core::num::NonZeroU32;
95 #[derive(PartialEq, Eq)]
97 index: NonZeroU32, // private
99 pub const FOO_ATOM: Atom = Atom { index: unsafe { NonZeroU32::new_unchecked(7) } };
103 ("foo") => { atom::FOO_ATOM }
107 fn test_match_nonzero_const_pattern() {
109 // Using as a pattern is supported by the compiler:
111 _ => panic!("Expected the const item as a pattern to match.")
116 fn test_from_nonzero() {
117 let nz = NonZeroU32::new(1).unwrap();
118 let num: u32 = nz.into();
119 assert_eq!(num, 1u32);