Forward Iterator::{ne, lt, le, gt, ge} to Iterator::{eq, partial_cmp}
This commit is contained in:
parent
070cebd0aa
commit
079d9b1051
@ -2435,145 +2435,67 @@ pub trait Iterator {
|
|||||||
/// Determines if the elements of this `Iterator` are unequal to those of
|
/// Determines if the elements of this `Iterator` are unequal to those of
|
||||||
/// another.
|
/// another.
|
||||||
#[stable(feature = "iter_order", since = "1.5.0")]
|
#[stable(feature = "iter_order", since = "1.5.0")]
|
||||||
fn ne<I>(mut self, other: I) -> bool where
|
fn ne<I>(self, other: I) -> bool where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
Self::Item: PartialEq<I::Item>,
|
Self::Item: PartialEq<I::Item>,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let mut other = other.into_iter();
|
!self.eq(other)
|
||||||
|
|
||||||
loop {
|
|
||||||
let x = match self.next() {
|
|
||||||
None => return other.next().is_some(),
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
let y = match other.next() {
|
|
||||||
None => return true,
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
if x != y { return true }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if the elements of this `Iterator` are lexicographically
|
/// Determines if the elements of this `Iterator` are lexicographically
|
||||||
/// less than those of another.
|
/// less than those of another.
|
||||||
#[stable(feature = "iter_order", since = "1.5.0")]
|
#[stable(feature = "iter_order", since = "1.5.0")]
|
||||||
fn lt<I>(mut self, other: I) -> bool where
|
fn lt<I>(self, other: I) -> bool where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
Self::Item: PartialOrd<I::Item>,
|
Self::Item: PartialOrd<I::Item>,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let mut other = other.into_iter();
|
match self.partial_cmp(other) {
|
||||||
|
Some(Ordering::Less) => true,
|
||||||
loop {
|
_ => false,
|
||||||
let x = match self.next() {
|
|
||||||
None => return other.next().is_some(),
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
let y = match other.next() {
|
|
||||||
None => return false,
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
match x.partial_cmp(&y) {
|
|
||||||
Some(Ordering::Less) => return true,
|
|
||||||
Some(Ordering::Equal) => (),
|
|
||||||
Some(Ordering::Greater) => return false,
|
|
||||||
None => return false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if the elements of this `Iterator` are lexicographically
|
/// Determines if the elements of this `Iterator` are lexicographically
|
||||||
/// less or equal to those of another.
|
/// less or equal to those of another.
|
||||||
#[stable(feature = "iter_order", since = "1.5.0")]
|
#[stable(feature = "iter_order", since = "1.5.0")]
|
||||||
fn le<I>(mut self, other: I) -> bool where
|
fn le<I>(self, other: I) -> bool where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
Self::Item: PartialOrd<I::Item>,
|
Self::Item: PartialOrd<I::Item>,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let mut other = other.into_iter();
|
match self.partial_cmp(other) {
|
||||||
|
Some(Ordering::Less) | Some(Ordering::Equal) => true,
|
||||||
loop {
|
_ => false,
|
||||||
let x = match self.next() {
|
|
||||||
None => { other.next(); return true; },
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
let y = match other.next() {
|
|
||||||
None => return false,
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
match x.partial_cmp(&y) {
|
|
||||||
Some(Ordering::Less) => return true,
|
|
||||||
Some(Ordering::Equal) => (),
|
|
||||||
Some(Ordering::Greater) => return false,
|
|
||||||
None => return false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if the elements of this `Iterator` are lexicographically
|
/// Determines if the elements of this `Iterator` are lexicographically
|
||||||
/// greater than those of another.
|
/// greater than those of another.
|
||||||
#[stable(feature = "iter_order", since = "1.5.0")]
|
#[stable(feature = "iter_order", since = "1.5.0")]
|
||||||
fn gt<I>(mut self, other: I) -> bool where
|
fn gt<I>(self, other: I) -> bool where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
Self::Item: PartialOrd<I::Item>,
|
Self::Item: PartialOrd<I::Item>,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let mut other = other.into_iter();
|
match self.partial_cmp(other) {
|
||||||
|
Some(Ordering::Greater) => true,
|
||||||
loop {
|
_ => false,
|
||||||
let x = match self.next() {
|
|
||||||
None => { other.next(); return false; },
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
let y = match other.next() {
|
|
||||||
None => return true,
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
match x.partial_cmp(&y) {
|
|
||||||
Some(Ordering::Less) => return false,
|
|
||||||
Some(Ordering::Equal) => (),
|
|
||||||
Some(Ordering::Greater) => return true,
|
|
||||||
None => return false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if the elements of this `Iterator` are lexicographically
|
/// Determines if the elements of this `Iterator` are lexicographically
|
||||||
/// greater than or equal to those of another.
|
/// greater than or equal to those of another.
|
||||||
#[stable(feature = "iter_order", since = "1.5.0")]
|
#[stable(feature = "iter_order", since = "1.5.0")]
|
||||||
fn ge<I>(mut self, other: I) -> bool where
|
fn ge<I>(self, other: I) -> bool where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
Self::Item: PartialOrd<I::Item>,
|
Self::Item: PartialOrd<I::Item>,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let mut other = other.into_iter();
|
match self.partial_cmp(other) {
|
||||||
|
Some(Ordering::Greater) | Some(Ordering::Equal) => true,
|
||||||
loop {
|
_ => false,
|
||||||
let x = match self.next() {
|
|
||||||
None => return other.next().is_none(),
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
let y = match other.next() {
|
|
||||||
None => return true,
|
|
||||||
Some(val) => val,
|
|
||||||
};
|
|
||||||
|
|
||||||
match x.partial_cmp(&y) {
|
|
||||||
Some(Ordering::Less) => return false,
|
|
||||||
Some(Ordering::Equal) => (),
|
|
||||||
Some(Ordering::Greater) => return true,
|
|
||||||
None => return false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user