From 9983afb7079b8f699ea29ba01e90b95e67f10d63 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Mon, 25 Nov 2024 10:32:53 +0400 Subject: [PATCH] feat(core/addr): make `NodeNo::from_bits` const --- elfo-core/src/addr.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/elfo-core/src/addr.rs b/elfo-core/src/addr.rs index e9a81415..7cf3b769 100644 --- a/elfo-core/src/addr.rs +++ b/elfo-core/src/addr.rs @@ -28,12 +28,15 @@ impl NodeNo { } #[inline] - pub fn from_bits(bits: u16) -> Option { - NonZeroU16::new(bits).map(NodeNo) + pub const fn from_bits(bits: u16) -> Option { + match NonZeroU16::new(bits) { + Some(node_no) => Some(Self(node_no)), + None => None, + } } #[inline] - pub fn into_bits(self) -> u16 { + pub const fn into_bits(self) -> u16 { self.0.get() } }