Skip to content

Commit

Permalink
https://github.com/rust-lang/rust/pull/92284
Browse files Browse the repository at this point in the history
  • Loading branch information
A1-Triard committed Apr 17, 2023
1 parent 486ef0d commit fbbbfc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "int-vec-2d"
version = "0.1.1"
version = "0.1.2"
#rust-version = "nightly"
authors = ["warlock <internalmike@gmail.com>"]
description = "Vectors, points, rectangles, etc. with `i16` coordinates."
Expand Down
28 changes: 12 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use core::cmp::{min, max};
use core::iter::{DoubleEndedIterator, FusedIterator, Iterator, TrustedLen};
use core::num::NonZeroI16;
use core::num::{NonZeroI16, NonZeroUsize};
use core::ops::{Add, AddAssign, Sub, SubAssign, Neg, Index, IndexMut};
use core::option::{Option};
use either::{Either, Left, Right};
Expand Down Expand Up @@ -142,11 +142,10 @@ impl Iterator for Range1d {
if self.is_empty() { None } else { Some(self.end) }
}

fn advance_by(&mut self, n: usize) -> Result<(), usize> {
let len = self.len();
if n > len {
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
if let Some(rem) = n.checked_sub(self.len()).and_then(NonZeroUsize::new) {
self.start = self.end;
return Err(len);
return Err(rem);
}
self.start = self.start.wrapping_add(n as u16 as i16);
Ok(())
Expand All @@ -166,11 +165,10 @@ impl DoubleEndedIterator for Range1d {
}
}

fn advance_back_by(&mut self, n: usize) -> Result<(), usize> {
let len = self.len();
if n > len {
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
if let Some(rem) = n.checked_sub(self.len()).and_then(NonZeroUsize::new) {
self.end = self.start;
return Err(len);
return Err(rem);
}
self.end = self.end.wrapping_sub(n as u16 as i16);
Ok(())
Expand Down Expand Up @@ -662,13 +660,11 @@ impl Iterator for RectPoints {
if self.rect.is_empty() { None } else { Some(self.rect.br_inner()) }
}

fn advance_by(&mut self, n: usize) -> Result<(), usize> {
if let Some(size) = self.size_hint().1 {
if n > size {
self.x = self.rect.l();
self.rect.tl = self.rect.bl();
return Err(size);
}
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
if let Some(rem) = self.size_hint().1.and_then(|len| n.checked_sub(len)).and_then(NonZeroUsize::new) {
self.x = self.rect.l();
self.rect.tl = self.rect.bl();
return Err(rem);
}
let n = n as u32;
let current_line_last = self.rect.r().wrapping_sub(self.x) as u16 as u32;
Expand Down

0 comments on commit fbbbfc3

Please sign in to comment.