Skip to content

Commit

Permalink
Enabled constant evaluation of Rust Version/Mask functions/methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
nayuki committed Feb 17, 2023
1 parent 5d9ec8d commit 2643e82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions rust-no-heap/src/lib.rs
Expand Up @@ -1432,13 +1432,13 @@ impl Version {
/// Creates a version object from the given number.
///
/// Panics if the number is outside the range [1, 40].
pub fn new(ver: u8) -> Self {
pub const fn new(ver: u8) -> Self {
assert!(Version::MIN.value() <= ver && ver <= Version::MAX.value(), "Version number out of range");
Self(ver)
}

/// Returns the value, which is in the range [1, 40].
pub fn value(self) -> u8 {
pub const fn value(self) -> u8 {
self.0
}

Expand All @@ -1459,13 +1459,13 @@ impl Mask {
/// Creates a mask object from the given number.
///
/// Panics if the number is outside the range [0, 7].
pub fn new(mask: u8) -> Self {
pub const fn new(mask: u8) -> Self {
assert!(mask <= 7, "Mask value out of range");
Self(mask)
}

/// Returns the value, which is in the range [0, 7].
pub fn value(self) -> u8 {
pub const fn value(self) -> u8 {
self.0
}
}
Expand Down
8 changes: 4 additions & 4 deletions rust/src/lib.rs
Expand Up @@ -1265,13 +1265,13 @@ impl Version {
/// Creates a version object from the given number.
///
/// Panics if the number is outside the range [1, 40].
pub fn new(ver: u8) -> Self {
pub const fn new(ver: u8) -> Self {
assert!(Version::MIN.value() <= ver && ver <= Version::MAX.value(), "Version number out of range");
Self(ver)
}

/// Returns the value, which is in the range [1, 40].
pub fn value(self) -> u8 {
pub const fn value(self) -> u8 {
self.0
}
}
Expand All @@ -1285,13 +1285,13 @@ impl Mask {
/// Creates a mask object from the given number.
///
/// Panics if the number is outside the range [0, 7].
pub fn new(mask: u8) -> Self {
pub const fn new(mask: u8) -> Self {
assert!(mask <= 7, "Mask value out of range");
Self(mask)
}

/// Returns the value, which is in the range [0, 7].
pub fn value(self) -> u8 {
pub const fn value(self) -> u8 {
self.0
}
}
Expand Down

0 comments on commit 2643e82

Please sign in to comment.