From c35b6bba38b437c76a4bf44dfb84f29d55f381a0 Mon Sep 17 00:00:00 2001 From: Alex Shelkovnykov Date: Thu, 14 Mar 2024 15:41:37 -0600 Subject: [PATCH] noun: minor improvement to slot implementation --- rust/ares/src/noun.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/rust/ares/src/noun.rs b/rust/ares/src/noun.rs index 39066fa..3ce5f80 100644 --- a/rust/ares/src/noun.rs +++ b/rust/ares/src/noun.rs @@ -692,8 +692,8 @@ impl Slots for Cell {} impl private::RawSlots for Cell { fn raw_slot(&self, axis: &BitSlice) -> Result { let mut noun: Noun = self.as_noun(); - // Panic because all of the logic to guard against this is in Noun::RawSlots, Noun::Slots - let mut cursor = axis.last_one().expect("raw_slot somehow by-passed 0 check"); + // Axis cannot be 0 + let mut cursor = axis.last_one().ok_or(Error::NotRepresentable)?; while cursor != 0 { cursor -= 1; @@ -1296,12 +1296,7 @@ pub trait Slots: private::RawSlots { * Retrieve component Noun at given axis, or fail with descriptive error */ fn slot(&self, axis: u64) -> Result { - if axis == 0 { - // 0 is not allowed as an axis - Err(Error::NotRepresentable) - } else { - self.raw_slot(BitSlice::from_element(&axis)) - } + self.raw_slot(BitSlice::from_element(&axis)) } /**