2026: fmt
This commit is contained in:
2 files changed
+5
-23
No files matched your search
+3
-15
@@ -417,13 +417,7 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
|
|||||||
self.data
|
self.data
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find_map(|(pos, val)| {
|
.find_map(|(pos, val)| if val == needle { Some(pos as i64) } else { None })
|
||||||
if val == needle {
|
|
||||||
Some(pos as i64)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap_or(-1),
|
.unwrap_or(-1),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -439,10 +433,7 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn forward_slice<C: AsCoord2d>(&self, start: &C, len: i64) -> Option<&[T]> {
|
pub fn forward_slice<C: AsCoord2d>(&self, start: &C, len: i64) -> Option<&[T]> {
|
||||||
let pos = (
|
let pos = (self.valid_pos(start), self.valid_pos(&(start.x() + len - 1, start.y())));
|
||||||
self.valid_pos(start),
|
|
||||||
self.valid_pos(&(start.x() + len - 1, start.y())),
|
|
||||||
);
|
|
||||||
match pos {
|
match pos {
|
||||||
(Some(pos1), Some(pos2)) => Some(&self.data[pos1..pos2 + 1]),
|
(Some(pos1), Some(pos2)) => Some(&self.data[pos1..pos2 + 1]),
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -627,10 +618,7 @@ impl Display for Grid<u8> {
|
|||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
for y in 0..self.height() {
|
for y in 0..self.height() {
|
||||||
for x in 0..self.width() {
|
for x in 0..self.width() {
|
||||||
f.write_fmt(format_args!(
|
f.write_fmt(format_args!("{}", *self.get(&(x as i64, y as i64)).unwrap() as char))?;
|
||||||
"{}",
|
|
||||||
*self.get(&(x as i64, y as i64)).unwrap() as char
|
|
||||||
))?;
|
|
||||||
}
|
}
|
||||||
f.write_char('\n')?;
|
f.write_char('\n')?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ pub struct RangeSet<T: Ord> {
|
|||||||
pub store: RBTree<NaiveRangeAdapter<T>>,
|
pub store: RBTree<NaiveRangeAdapter<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_range<R: RangeBounds<T>, T: Copy + Ord + Add<Output = T> + From<u8>>(
|
fn normalize_range<R: RangeBounds<T>, T: Copy + Ord + Add<Output = T> + From<u8>>(r: &R) -> NaiveRange<T> {
|
||||||
r: &R,
|
|
||||||
) -> NaiveRange<T> {
|
|
||||||
let start = match r.start_bound() {
|
let start = match r.start_bound() {
|
||||||
Bound::Included(x) => *x,
|
Bound::Included(x) => *x,
|
||||||
Bound::Excluded(x) => *x + T::from(1),
|
Bound::Excluded(x) => *x + T::from(1),
|
||||||
@@ -114,11 +112,7 @@ mod tests {
|
|||||||
set.add(&(2000..2001));
|
set.add(&(2000..2001));
|
||||||
set.add(&(-10..-2));
|
set.add(&(-10..-2));
|
||||||
set.add(&(-1..-1));
|
set.add(&(-1..-1));
|
||||||
let end = set
|
let end = set.store.iter().map(|r| (r.start, r.end)).collect::<Vec<_>>();
|
||||||
.store
|
|
||||||
.iter()
|
|
||||||
.map(|r| (r.start, r.end))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
assert_eq!(end, [(-10, 10), (50, 2001)])
|
assert_eq!(end, [(-10, 10), (50, 2001)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user