Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit a245328

Browse files
authored
Merge pull request #220 from urbit/as/slice
Minor improvement to slot implementation
2 parents f96297d + c35b6bb commit a245328

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

rust/ares/src/noun.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ impl Slots for Cell {}
692692
impl private::RawSlots for Cell {
693693
fn raw_slot(&self, axis: &BitSlice<u64, Lsb0>) -> Result<Noun> {
694694
let mut noun: Noun = self.as_noun();
695-
// Panic because all of the logic to guard against this is in Noun::RawSlots, Noun::Slots
696-
let mut cursor = axis.last_one().expect("raw_slot somehow by-passed 0 check");
695+
// Axis cannot be 0
696+
let mut cursor = axis.last_one().ok_or(Error::NotRepresentable)?;
697697

698698
while cursor != 0 {
699699
cursor -= 1;
@@ -1296,12 +1296,7 @@ pub trait Slots: private::RawSlots {
12961296
* Retrieve component Noun at given axis, or fail with descriptive error
12971297
*/
12981298
fn slot(&self, axis: u64) -> Result<Noun> {
1299-
if axis == 0 {
1300-
// 0 is not allowed as an axis
1301-
Err(Error::NotRepresentable)
1302-
} else {
1303-
self.raw_slot(BitSlice::from_element(&axis))
1304-
}
1299+
self.raw_slot(BitSlice::from_element(&axis))
13051300
}
13061301

13071302
/**

0 commit comments

Comments
 (0)