Skip to content

Commit b9e0f3b

Browse files
committed
Make NonZero<char> possible
1 parent 2b96ddc commit b9e0f3b

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

library/core/src/num/niche_types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ define_valid_range_type! {
131131
pub struct NonZeroI32Inner(i32 as u32 in 1..=0xffff_ffff);
132132
pub struct NonZeroI64Inner(i64 as u64 in 1..=0xffffffff_ffffffff);
133133
pub struct NonZeroI128Inner(i128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff);
134+
135+
pub struct NonZeroCharInner(char as u32 in 1..=0x10ffff);
134136
}
135137

136138
#[cfg(target_pointer_width = "16")]

library/core/src/num/nonzero.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl_zeroable_primitive!(
7979
NonZeroI64Inner(i64),
8080
NonZeroI128Inner(i128),
8181
NonZeroIsizeInner(isize),
82+
NonZeroCharInner(char),
8283
);
8384

8485
/// A value that is known not to equal zero.

library/coretests/tests/num/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@ mod u64;
2222
mod u8;
2323

2424
mod bignum;
25-
2625
mod const_from;
2726
mod dec2flt;
27+
mod float_iter_sum_identity;
2828
mod flt2dec;
29+
mod ieee754;
2930
mod int_log;
3031
mod int_sqrt;
3132
mod midpoint;
33+
mod nan;
34+
mod niche_types;
3235
mod ops;
3336
mod wrapping;
3437

35-
mod float_iter_sum_identity;
36-
mod ieee754;
37-
mod nan;
38-
3938
/// Adds the attribute to all items in the block.
4039
macro_rules! cfg_block {
4140
($(#[$attr:meta]{$($it:item)*})*) => {$($(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use core::num::NonZero;
2+
3+
#[test]
4+
fn test_new_from_zero_is_none() {
5+
assert_eq!(NonZero::<char>::new(0 as char), None);
6+
}
7+
8+
#[test]
9+
fn test_new_from_extreme_is_some() {
10+
assert!(NonZero::<char>::new(1 as char).is_some());
11+
assert!(NonZero::<char>::new(char::MAX).is_some());
12+
}

0 commit comments

Comments
 (0)