mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
Specialize if
This commit is contained in:
parent
2ca829aaa8
commit
0585f32039
7 changed files with 186 additions and 11 deletions
|
@ -274,3 +274,37 @@ impl<T> IntoIterator for NonEmptySlice<T> {
|
|||
self.inner.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// Like `Slice`, but for pairs of `T`
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone)]
|
||||
pub struct PairSlice<T>(Slice<T>);
|
||||
|
||||
impl<T> PairSlice<T> {
|
||||
pub const fn start(self) -> u32 {
|
||||
self.0.start()
|
||||
}
|
||||
|
||||
pub const fn empty() -> Self {
|
||||
Self(Slice::empty())
|
||||
}
|
||||
|
||||
pub const fn len(&self) -> usize {
|
||||
self.0.len() / 2
|
||||
}
|
||||
|
||||
pub fn indices_iter(&self) -> impl Iterator<Item = (usize, usize)> {
|
||||
(self.0.start as usize..(self.0.start as usize + self.0.length as usize))
|
||||
.step_by(2)
|
||||
.map(|i| (i, i + 1))
|
||||
}
|
||||
|
||||
pub const fn new(start: u32, length: u16) -> Self {
|
||||
Self(Slice::new(start, length * 2))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for PairSlice<T> {
|
||||
fn default() -> Self {
|
||||
Self(Slice::default())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue