Skip to content

Commit

Permalink
Add CellSlice::shrink
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Oct 15, 2023
1 parent ed3032c commit a5d1432
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cell/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,18 @@ impl<'a> CellSlice<'a> {
}
}

/// Shrinks the slice down to a prefix of the specified length.
pub fn shrink(&mut self, bits: Option<u16>, refs: Option<u8>) -> Result<(), Error> {
let bits = bits.unwrap_or_else(|| self.remaining_bits());
let refs = refs.unwrap_or_else(|| self.remaining_refs());
if self.has_remaining(bits, refs) {
*self = self.get_prefix(bits, refs);
Ok(())
} else {
Err(Error::CellUnderflow)
}
}

/// Returns a subslice with the data prefix removed.
///
/// If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`.
Expand Down

0 comments on commit a5d1432

Please sign in to comment.