Skip to content

Commit

Permalink
feat(core/addr): make NodeNo::from_bits const
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Nov 25, 2024
1 parent 8380ed9 commit 9983afb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions elfo-core/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ impl NodeNo {
}

#[inline]
pub fn from_bits(bits: u16) -> Option<Self> {
NonZeroU16::new(bits).map(NodeNo)
pub const fn from_bits(bits: u16) -> Option<Self> {
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()
}
}
Expand Down

0 comments on commit 9983afb

Please sign in to comment.