Skip to content

Commit

Permalink
Bootstrapping preparation for the library
Browse files Browse the repository at this point in the history
Since just `ops::Try` will need to change meaning.
  • Loading branch information
scottmcm committed May 6, 2021
1 parent d44f647 commit c10eec3
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 104 deletions.
6 changes: 3 additions & 3 deletions library/alloc/src/collections/vec_deque/iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::fmt;
use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess};
use core::ops::Try;
use core::ops::TryWhereOutputEquals;

use super::{count, wrap_index, RingSlices};

Expand Down Expand Up @@ -66,7 +66,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
R: TryWhereOutputEquals<B>,
{
let (mut iter, final_res);
if self.tail <= self.head {
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
R: TryWhereOutputEquals<B>,
{
let (mut iter, final_res);
if self.tail <= self.head {
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
#![feature(alloc_layout_extra)]
#![feature(trusted_random_access)]
#![feature(try_trait)]
#![feature(try_trait_transition)]
#![feature(min_type_alias_impl_trait)]
#![feature(associated_type_bounds)]
#![feature(slice_group_by)]
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/iter/adapters/chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::iter::{DoubleEndedIterator, FusedIterator, Iterator, TrustedLen};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that links two iterators together, in a chain.
///
Expand Down Expand Up @@ -98,7 +98,7 @@ where
where
Self: Sized,
F: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
if let Some(ref mut a) = self.a {
acc = a.try_fold(acc, &mut f)?;
Expand Down Expand Up @@ -281,7 +281,7 @@ where
where
Self: Sized,
F: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
if let Some(ref mut b) = self.b {
acc = b.try_rfold(acc, &mut f)?;
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/iter/adapters/cloned.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::iter::adapters::{zip::try_get_unchecked, TrustedRandomAccess};
use crate::iter::{FusedIterator, TrustedLen};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that clones the elements of an underlying iterator.
///
Expand Down Expand Up @@ -46,7 +46,7 @@ where
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
R: TryWhereOutputEquals<B>,
{
self.it.try_fold(init, clone_try_fold(f))
}
Expand Down Expand Up @@ -82,7 +82,7 @@ where
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
R: TryWhereOutputEquals<B>,
{
self.it.try_rfold(init, clone_try_fold(f))
}
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/iter/adapters/copied.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::iter::adapters::{zip::try_get_unchecked, TrustedRandomAccess};
use crate::iter::{FusedIterator, TrustedLen};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that copies the elements of an underlying iterator.
///
Expand Down Expand Up @@ -50,7 +50,7 @@ where
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
R: TryWhereOutputEquals<B>,
{
self.it.try_fold(init, copy_try_fold(f))
}
Expand Down Expand Up @@ -98,7 +98,7 @@ where
where
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Ok = B>,
R: TryWhereOutputEquals<B>,
{
self.it.try_rfold(init, copy_try_fold(f))
}
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/iter/adapters/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{iter::FusedIterator, ops::Try};
use crate::{iter::FusedIterator, ops::TryWhereOutputEquals};

/// An iterator that repeats endlessly.
///
Expand Down Expand Up @@ -53,7 +53,7 @@ where
fn try_fold<Acc, F, R>(&mut self, mut acc: Acc, mut f: F) -> R
where
F: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
// fully iterate the current iterator. this is necessary because
// `self.iter` may be empty even when `self.orig` isn't
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/iter/adapters/enumerate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::iter::adapters::{zip::try_get_unchecked, SourceIter, TrustedRandomAccess};
use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that yields the current count and the element during iteration.
///
Expand Down Expand Up @@ -71,7 +71,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
#[inline]
fn enumerate<'a, T, Acc, R>(
Expand Down Expand Up @@ -150,7 +150,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
// Can safely add and subtract the count, as `ExactSizeIterator` promises
// that the number of elements fits into a `usize`.
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/iter/adapters/filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fmt;
use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that filters the elements of `iter` with `predicate`.
///
Expand Down Expand Up @@ -37,7 +37,7 @@ fn filter_fold<T, Acc>(
move |acc, item| if predicate(&item) { fold(acc, item) } else { acc }
}

fn filter_try_fold<'a, T, Acc, R: Try<Ok = Acc>>(
fn filter_try_fold<'a, T, Acc, R: TryWhereOutputEquals<Acc>>(
predicate: &'a mut impl FnMut(&T) -> bool,
mut fold: impl FnMut(Acc, T) -> R + 'a,
) -> impl FnMut(Acc, T) -> R + 'a {
Expand Down Expand Up @@ -88,7 +88,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.iter.try_fold(init, filter_try_fold(&mut self.predicate, fold))
}
Expand Down Expand Up @@ -117,7 +117,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.iter.try_rfold(init, filter_try_fold(&mut self.predicate, fold))
}
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/iter/adapters/filter_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fmt;
use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable};
use crate::ops::{ControlFlow, Try};
use crate::ops::{ControlFlow, TryWhereOutputEquals};

/// An iterator that uses `f` to both filter and map elements from `iter`.
///
Expand Down Expand Up @@ -39,7 +39,7 @@ fn filter_map_fold<T, B, Acc>(
}
}

fn filter_map_try_fold<'a, T, B, Acc, R: Try<Ok = Acc>>(
fn filter_map_try_fold<'a, T, B, Acc, R: TryWhereOutputEquals<Acc>>(
f: &'a mut impl FnMut(T) -> Option<B>,
mut fold: impl FnMut(Acc, B) -> R + 'a,
) -> impl FnMut(Acc, T) -> R + 'a {
Expand Down Expand Up @@ -72,7 +72,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.iter.try_fold(init, filter_map_try_fold(&mut self.f, fold))
}
Expand Down Expand Up @@ -111,7 +111,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.iter.try_rfold(init, filter_map_try_fold(&mut self.f, fold))
}
Expand Down
18 changes: 9 additions & 9 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fmt;
use crate::iter::{DoubleEndedIterator, Fuse, FusedIterator, Iterator, Map};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that maps each element to an iterator, and yields the elements
/// of the produced iterators.
Expand Down Expand Up @@ -61,7 +61,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.inner.try_fold(init, fold)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.inner.try_rfold(init, fold)
}
Expand Down Expand Up @@ -178,7 +178,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.inner.try_fold(init, fold)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.inner.try_rfold(init, fold)
}
Expand Down Expand Up @@ -293,10 +293,10 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
#[inline]
fn flatten<'a, T: IntoIterator, Acc, R: Try<Ok = Acc>>(
fn flatten<'a, T: IntoIterator, Acc, R: TryWhereOutputEquals<Acc>>(
frontiter: &'a mut Option<T::IntoIter>,
fold: &'a mut impl FnMut(Acc, T::Item) -> R,
) -> impl FnMut(Acc, T) -> R + 'a {
Expand Down Expand Up @@ -382,10 +382,10 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
#[inline]
fn flatten<'a, T: IntoIterator, Acc, R: Try<Ok = Acc>>(
fn flatten<'a, T: IntoIterator, Acc, R: TryWhereOutputEquals<Acc>>(
backiter: &'a mut Option<T::IntoIter>,
fold: &'a mut impl FnMut(Acc, T::Item) -> R,
) -> impl FnMut(Acc, T) -> R + 'a
Expand Down
18 changes: 9 additions & 9 deletions library/core/src/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::iter::adapters::{zip::try_get_unchecked, InPlaceIterable, SourceIter}
use crate::iter::{
DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess,
};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that yields `None` forever after the underlying iterator
/// yields `None` once.
Expand Down Expand Up @@ -92,7 +92,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
FuseImpl::try_fold(self, acc, fold)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
FuseImpl::try_rfold(self, acc, fold)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ trait FuseImpl<I> {
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>;
R: TryWhereOutputEquals<Acc>;
fn fold<Acc, Fold>(self, acc: Acc, fold: Fold) -> Acc
where
Fold: FnMut(Acc, Self::Item) -> Acc;
Expand All @@ -238,7 +238,7 @@ trait FuseImpl<I> {
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
I: DoubleEndedIterator;
fn rfold<Acc, Fold>(self, acc: Acc, fold: Fold) -> Acc
where
Expand Down Expand Up @@ -305,7 +305,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
if let Some(ref mut iter) = self.iter {
acc = iter.try_fold(acc, fold)?;
Expand Down Expand Up @@ -354,7 +354,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
I: DoubleEndedIterator,
{
if let Some(ref mut iter) = self.iter {
Expand Down Expand Up @@ -443,7 +443,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
unchecked!(self).try_fold(init, fold)
}
Expand Down Expand Up @@ -485,7 +485,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
I: DoubleEndedIterator,
{
unchecked!(self).try_rfold(init, fold)
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/iter/adapters/inspect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fmt;
use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable};
use crate::ops::Try;
use crate::ops::TryWhereOutputEquals;

/// An iterator that calls a function with a reference to each element before
/// yielding it.
Expand Down Expand Up @@ -87,7 +87,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.iter.try_fold(init, inspect_try_fold(&mut self.f, fold))
}
Expand Down Expand Up @@ -117,7 +117,7 @@ where
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
R: TryWhereOutputEquals<Acc>,
{
self.iter.try_rfold(init, inspect_try_fold(&mut self.f, fold))
}
Expand Down
Loading

0 comments on commit c10eec3

Please sign in to comment.