From 2643e824eb15064662e6c4d99b010740275a0be1 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 17 Feb 2023 23:53:35 +0000 Subject: [PATCH] Enabled constant evaluation of Rust Version/Mask functions/methods. --- rust-no-heap/src/lib.rs | 8 ++++---- rust/src/lib.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust-no-heap/src/lib.rs b/rust-no-heap/src/lib.rs index a70fd9e1..453d9f95 100644 --- a/rust-no-heap/src/lib.rs +++ b/rust-no-heap/src/lib.rs @@ -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 } @@ -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 } } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index bfe335e9..b4f2aaf7 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -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 } } @@ -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 } }