Skip to content

Commit 3701661

Browse files
committed
Switch back to short-circuiting || and && operators in const fn
Enabled by Rust 1.46 as part of const if/else.
1 parent 8605175 commit 3701661

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
rust: [1.41.1, stable, beta, nightly]
16+
rust: [1.46.0, stable, beta, nightly]
1717
steps:
1818
- uses: actions/checkout@v2
1919
- uses: hecrj/setup-rust-action@v1

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ ascii = { version = "1.1", default-features = false, features = ["alloc"] }
3535

3636
## Minimum supported Rust version
3737

38-
The minimum Rust version for 1.1.\* releases is 1.41.1.
38+
The minimum Rust version for 1.2.\* releases is 1.46.0.
3939
Later 1.y.0 releases might require newer Rust versions, but the three most
4040
recent stable releases at the time of publishing will always be supported.
4141
For example this means that if the current stable Rust version is 1.70 when
42-
ascii 1.2.0 is released, then ascii 1.2.\* will not require a newer
42+
ascii 1.3.0 is released, then ascii 1.3.\* will not require a newer
4343
Rust version than 1.68.
4444

4545
## History

src/ascii_char.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl AsciiChar {
411411
#[inline]
412412
#[must_use]
413413
pub const fn is_alphabetic(self) -> bool {
414-
(self.to_not_upper() >= b'a') & (self.to_not_upper() <= b'z')
414+
(self.to_not_upper() >= b'a') && (self.to_not_upper() <= b'z')
415415
}
416416

417417
/// Check if the character is a letter (a-z, A-Z).
@@ -457,14 +457,14 @@ impl AsciiChar {
457457
#[inline]
458458
#[must_use]
459459
pub const fn is_ascii_digit(&self) -> bool {
460-
(*self as u8 >= b'0') & (*self as u8 <= b'9')
460+
(*self as u8 >= b'0') && (*self as u8 <= b'9')
461461
}
462462

463463
/// Check if the character is a letter or number
464464
#[inline]
465465
#[must_use]
466466
pub const fn is_alphanumeric(self) -> bool {
467-
self.is_alphabetic() | self.is_ascii_digit()
467+
self.is_alphabetic() || self.is_ascii_digit()
468468
}
469469

470470
/// Check if the character is a letter or number
@@ -491,7 +491,7 @@ impl AsciiChar {
491491
#[inline]
492492
#[must_use]
493493
pub const fn is_ascii_blank(&self) -> bool {
494-
(*self as u8 == b' ') | (*self as u8 == b'\t')
494+
(*self as u8 == b' ') || (*self as u8 == b'\t')
495495
}
496496

497497
/// Check if the character one of ' ', '\t', '\n', '\r',
@@ -500,7 +500,7 @@ impl AsciiChar {
500500
#[must_use]
501501
pub const fn is_whitespace(self) -> bool {
502502
let b = self as u8;
503-
self.is_ascii_blank() | (b == b'\n') | (b == b'\r') | (b == 0x0b) | (b == 0x0c)
503+
self.is_ascii_blank() || (b == b'\n') || (b == b'\r') || (b == 0x0b) || (b == 0x0c)
504504
}
505505

506506
/// Check if the character is a ' ', '\t', '\n', '\r' or '\0xc' (form feed).
@@ -510,9 +510,9 @@ impl AsciiChar {
510510
#[must_use]
511511
pub const fn is_ascii_whitespace(&self) -> bool {
512512
self.is_ascii_blank()
513-
| (*self as u8 == b'\n')
514-
| (*self as u8 == b'\r')
515-
| (*self as u8 == 0x0c/*form feed*/)
513+
|| (*self as u8 == b'\n')
514+
|| (*self as u8 == b'\r')
515+
|| (*self as u8 == 0x0c/*form feed*/)
516516
}
517517

518518
/// Check if the character is a control character
@@ -530,7 +530,7 @@ impl AsciiChar {
530530
#[inline]
531531
#[must_use]
532532
pub const fn is_ascii_control(&self) -> bool {
533-
((*self as u8) < b' ') | (*self as u8 == 127)
533+
((*self as u8) < b' ') || (*self as u8 == 127)
534534
}
535535

536536
/// Checks if the character is printable (except space)
@@ -624,7 +624,7 @@ impl AsciiChar {
624624
#[inline]
625625
#[must_use]
626626
pub const fn is_ascii_punctuation(&self) -> bool {
627-
self.is_ascii_graphic() & !self.is_alphanumeric()
627+
self.is_ascii_graphic() && !self.is_alphanumeric()
628628
}
629629

630630
/// Checks if the character is a valid hex digit
@@ -641,7 +641,7 @@ impl AsciiChar {
641641
#[inline]
642642
#[must_use]
643643
pub const fn is_ascii_hexdigit(&self) -> bool {
644-
self.is_ascii_digit() | ((*self as u8 | 0x20_u8).wrapping_sub(b'a') < 6)
644+
self.is_ascii_digit() || ((*self as u8 | 0x20u8).wrapping_sub(b'a') < 6)
645645
}
646646

647647
/// Unicode has printable versions of the ASCII control codes, like '␛'.
@@ -728,7 +728,7 @@ impl AsciiChar {
728728
#[must_use]
729729
pub const fn eq_ignore_ascii_case(&self, other: &Self) -> bool {
730730
(self.as_byte() == other.as_byte())
731-
| (self.is_alphabetic() & (self.to_not_upper() == other.to_not_upper()))
731+
|| (self.is_alphabetic() && (self.to_not_upper() == other.to_not_upper()))
732732
}
733733
}
734734

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
//!
1616
//! # Minimum supported Rust version
1717
//!
18-
//! The minimum Rust version for 1.1.\* releases is 1.41.1.
18+
//! The minimum Rust version for 1.2.\* releases is 1.46.0.
1919
//! Later 1.y.0 releases might require newer Rust versions, but the three most
2020
//! recent stable releases at the time of publishing will always be supported.
2121
//! For example this means that if the current stable Rust version is 1.70 when
22-
//! ascii 1.2.0 is released, then ascii 1.2.\* will not require a newer
22+
//! ascii 1.3.0 is released, then ascii 1.3.\* will not require a newer
2323
//! Rust version than 1.68.
2424
//!
2525
//! # History

0 commit comments

Comments
 (0)