File tree Expand file tree Collapse file tree 2 files changed +5
-12
lines changed Expand file tree Collapse file tree 2 files changed +5
-12
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( const_panic) ]
1
2
#![ allow( clippy:: many_single_char_names) ]
2
3
#![ allow( clippy:: unreadable_literal) ]
3
4
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ pub struct ValidPrime {
13
13
}
14
14
15
15
impl ValidPrime {
16
- pub fn new ( p : u32 ) -> Self {
17
- assert ! ( is_valid_prime( p) , "Invalid prime: {}" , p ) ;
16
+ pub const fn new ( p : u32 ) -> Self {
17
+ assert ! ( is_valid_prime( p) ) ;
18
18
19
19
#[ cfg( not( feature = "prime-two" ) ) ]
20
20
{ Self { p } }
@@ -30,14 +30,6 @@ impl ValidPrime {
30
30
None
31
31
}
32
32
}
33
-
34
- /// Create a ValidPrime without checking the number is a valid prime. Calling with an invalid
35
- /// value invokes undefined behaviour. The main reason for this is that
36
- /// [ValidPrime::new](ValidPrime::new) is not const due to the checks. If the checked version
37
- /// can be made const, we can remove this function
38
- pub const unsafe fn new_unsafe ( p : u32 ) -> Self {
39
- Self { p }
40
- }
41
33
}
42
34
43
35
impl std:: ops:: Deref for ValidPrime {
@@ -86,12 +78,12 @@ impl<'de> Deserialize<'de> for ValidPrime {
86
78
}
87
79
88
80
#[ cfg( not( feature = "prime-two" ) ) ]
89
- pub fn is_valid_prime ( p : u32 ) -> bool {
81
+ pub const fn is_valid_prime ( p : u32 ) -> bool {
90
82
( p as usize ) < MAX_PRIME && PRIME_TO_INDEX_MAP [ p as usize ] != NOT_A_PRIME
91
83
}
92
84
93
85
#[ cfg( feature = "prime-two" ) ]
94
- pub fn is_valid_prime ( p : u32 ) -> bool {
86
+ pub const fn is_valid_prime ( p : u32 ) -> bool {
95
87
p == 2
96
88
}
97
89
You can’t perform that action at this time.
0 commit comments