Merge pull request #220 from urbit/as/slice

Minor improvement to slot implementation
This commit is contained in:
Edward Amsden 2024-03-19 14:43:14 -05:00 committed by GitHub
commit a245328266
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -692,8 +692,8 @@ impl Slots for Cell {}
impl private::RawSlots for Cell { impl private::RawSlots for Cell {
fn raw_slot(&self, axis: &BitSlice<u64, Lsb0>) -> Result<Noun> { fn raw_slot(&self, axis: &BitSlice<u64, Lsb0>) -> Result<Noun> {
let mut noun: Noun = self.as_noun(); let mut noun: Noun = self.as_noun();
// Panic because all of the logic to guard against this is in Noun::RawSlots, Noun::Slots // Axis cannot be 0
let mut cursor = axis.last_one().expect("raw_slot somehow by-passed 0 check"); let mut cursor = axis.last_one().ok_or(Error::NotRepresentable)?;
while cursor != 0 { while cursor != 0 {
cursor -= 1; cursor -= 1;
@ -1296,13 +1296,8 @@ pub trait Slots: private::RawSlots {
* Retrieve component Noun at given axis, or fail with descriptive error * Retrieve component Noun at given axis, or fail with descriptive error
*/ */
fn slot(&self, axis: u64) -> Result<Noun> { fn slot(&self, axis: u64) -> Result<Noun> {
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))
} }
}
/** /**
* Retrieve component Noun at axis given as Atom, or fail with descriptive error * Retrieve component Noun at axis given as Atom, or fail with descriptive error