1
0
Fork 0
forked from wry/wry

all: split reusable components into workspace crates

This commit is contained in:
kossLAN 2026-05-29 09:14:53 -04:00
parent 2a079ed800
commit 657e7ce2f7
No known key found for this signature in database
225 changed files with 7422 additions and 17602 deletions

35
utils/src/vecdeque_ext.rs Normal file
View file

@ -0,0 +1,35 @@
use std::{
collections::{Bound, VecDeque},
ops::RangeBounds,
};
pub trait VecDequeExt<T> {
fn get_slices(&self, range: impl RangeBounds<usize>) -> (&[T], &[T]);
}
impl<T> VecDequeExt<T> for VecDeque<T> {
fn get_slices(&self, range: impl RangeBounds<usize>) -> (&[T], &[T]) {
let (l, r) = self.as_slices();
let start = match range.start_bound().cloned() {
Bound::Included(n) => n,
Bound::Excluded(n) => n + 1,
Bound::Unbounded => 0,
};
let end = match range.end_bound().cloned() {
Bound::Included(n) => n + 1,
Bound::Excluded(n) => n,
Bound::Unbounded => self.len(),
};
let left = {
let lo = start.min(l.len());
let hi = end.min(l.len());
&l[lo..hi]
};
let right = {
let lo = start.saturating_sub(l.len());
let hi = end.saturating_sub(l.len());
&r[lo..hi]
};
(left, right)
}
}