Skip to content

fix stream code style #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/stream/stream/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ pub struct AllFuture<'a, S, F, T> {
pub(crate) _marker: PhantomData<T>,
}

impl<'a, S, F, T> AllFuture<'a, S, F, T> {
pub(crate) fn new(stream: &'a mut S, f: F) -> Self {
Self {
stream,
f,
result: true, // the default if the empty stream
_marker: PhantomData,
}
}
}

impl<S: Unpin, F, T> Unpin for AllFuture<'_, S, F, T> {}

impl<S, F> Future for AllFuture<'_, S, F, S::Item>
Expand Down
11 changes: 11 additions & 0 deletions src/stream/stream/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ pub struct AnyFuture<'a, S, F, T> {
pub(crate) _marker: PhantomData<T>,
}

impl<'a, S, F, T> AnyFuture<'a, S, F, T> {
pub(crate) fn new(stream: &'a mut S, f: F) -> Self {
Self {
stream,
f,
result: false, // the default if the empty stream
_marker: PhantomData,
}
}
}

impl<S: Unpin, F, T> Unpin for AnyFuture<'_, S, F, T> {}

impl<S, F> Future for AnyFuture<'_, S, F, S::Item>
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pin_project! {

impl<S: Stream, U: Stream> Chain<S, U> {
pub(super) fn new(first: S, second: U) -> Self {
Chain {
Self {
first: first.fuse(),
second: second.fuse(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pin_project! {

impl<L: Stream, R: Stream> CmpFuture<L, R> {
pub(super) fn new(l: L, r: R) -> Self {
CmpFuture {
Self {
l: l.fuse(),
r: r.fuse(),
l_cache: None,
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pin_project! {

impl<S> Copied<S> {
pub(super) fn new(stream: S) -> Self {
Copied { stream }
Self { stream }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pin_project! {

impl<S> CountFuture<S> {
pub(crate) fn new(stream: S) -> Self {
CountFuture { stream, count: 0 }
Self { stream, count: 0 }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stream/stream/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl<S> Cycle<S>
where
S: Stream + Clone,
{
pub fn new(source: S) -> Cycle<S> {
Cycle {
pub(crate) fn new(source: S) -> Self {
Self {
orig: source.clone(),
source: ManuallyDrop::new(source),
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pin_project! {

impl<S> Enumerate<S> {
pub(super) fn new(stream: S) -> Self {
Enumerate { stream, i: 0 }
Self { stream, i: 0 }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
L::Item: PartialEq<R::Item>,
{
pub(super) fn new(l: L, r: R) -> Self {
EqFuture {
Self {
l: l.fuse(),
r: r.fuse(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pin_project! {

impl<S, P> Filter<S, P> {
pub(super) fn new(stream: S, predicate: P) -> Self {
Filter {
Self {
stream,
predicate,
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pin_project! {

impl<S, F> FilterMap<S, F> {
pub(crate) fn new(stream: S, f: F) -> Self {
FilterMap { stream, f }
Self { stream, f }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct FindFuture<'a, S, P> {

impl<'a, S, P> FindFuture<'a, S, P> {
pub(super) fn new(stream: &'a mut S, p: P) -> Self {
FindFuture { stream, p }
Self { stream, p }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/find_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct FindMapFuture<'a, S, F> {

impl<'a, S, F> FindMapFuture<'a, S, F> {
pub(super) fn new(stream: &'a mut S, f: F) -> Self {
FindMapFuture { stream, f }
Self { stream, f }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stream/stream/flat_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ where
U: IntoStream,
F: FnMut(S::Item) -> U,
{
pub(super) fn new(stream: S, f: F) -> FlatMap<S, U, F> {
FlatMap {
pub(super) fn new(stream: S, f: F) -> Self {
Self {
stream: stream.map(f),
inner_stream: None,
}
Expand Down
4 changes: 2 additions & 2 deletions src/stream/stream/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ where
S: Stream,
S::Item: IntoStream,
{
pub(super) fn new(stream: S) -> Flatten<S> {
Flatten {
pub(super) fn new(stream: S) -> Self {
Self {
stream,
inner_stream: None,
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pin_project! {

impl<S, F, B> FoldFuture<S, F, B> {
pub(super) fn new(stream: S, init: B, f: F) -> Self {
FoldFuture {
Self {
stream,
f,
acc: Some(init),
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/for_each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pin_project! {

impl<S, F> ForEachFuture<S, F> {
pub(super) fn new(stream: S, f: F) -> Self {
ForEachFuture {
Self {
stream,
f,
}
Expand Down
9 changes: 9 additions & 0 deletions src/stream/stream/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ pin_project! {
}
}

impl<S> Fuse<S> {
pub(super) fn new(stream: S) -> Self {
Self {
stream,
done: false,
}
}
}

impl<S: Stream> Stream for Fuse<S> {
type Item = S::Item;

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/ge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
L::Item: PartialOrd<R::Item>,
{
pub(super) fn new(l: L, r: R) -> Self {
GeFuture {
Self {
partial_cmp: l.partial_cmp(r),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/gt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
L::Item: PartialOrd<R::Item>,
{
pub(super) fn new(l: L, r: R) -> Self {
GtFuture {
Self {
partial_cmp: l.partial_cmp(r),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pin_project! {

impl<S, F> Inspect<S, F> {
pub(super) fn new(stream: S, f: F) -> Self {
Inspect {
Self {
stream,
f,
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pin_project! {

impl<S, T> LastFuture<S, T> {
pub(crate) fn new(stream: S) -> Self {
LastFuture { stream, last: None }
Self { stream, last: None }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
L::Item: PartialOrd<R::Item>,
{
pub(super) fn new(l: L, r: R) -> Self {
LeFuture {
Self {
partial_cmp: l.partial_cmp(r),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/lt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
L::Item: PartialOrd<R::Item>,
{
pub(super) fn new(l: L, r: R) -> Self {
LtFuture {
Self {
partial_cmp: l.partial_cmp(r),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pin_project! {

impl<S, F> Map<S, F> {
pub(crate) fn new(stream: S, f: F) -> Self {
Map {
Self {
stream,
f,
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/max_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pin_project! {

impl<S, F, T> MaxByFuture<S, F, T> {
pub(super) fn new(stream: S, compare: F) -> Self {
MaxByFuture {
Self {
stream,
compare,
max: None,
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/min_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pin_project! {

impl<S, F, T> MinByFuture<S, F, T> {
pub(super) fn new(stream: S, compare: F) -> Self {
MinByFuture {
Self {
stream,
compare,
min: None,
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/min_by_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pin_project! {

impl<S, T, K> MinByKeyFuture<S, T, K> {
pub(super) fn new(stream: S, key_by: K) -> Self {
MinByKeyFuture {
Self {
stream,
min: None,
key_by,
Expand Down
27 changes: 5 additions & 22 deletions src/stream/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub use take_while::TakeWhile;
pub use zip::Zip;

use std::cmp::Ordering;
use std::marker::PhantomData;

cfg_unstable! {
use std::future::Future;
Expand Down Expand Up @@ -288,10 +287,7 @@ extension_trait! {
where
Self: Sized,
{
Take {
stream: self,
remaining: n,
}
Take::new(self, n)
}

#[doc = r#"
Expand Down Expand Up @@ -714,10 +710,7 @@ extension_trait! {
where
Self: Sized,
{
Fuse {
stream: self,
done: false,
}
Fuse::new(self)
}

#[doc = r#"
Expand Down Expand Up @@ -1193,12 +1186,7 @@ extension_trait! {
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool,
{
AllFuture {
stream: self,
result: true, // the default if the empty stream
_marker: PhantomData,
f,
}
AllFuture::new(self, f)
}

#[doc = r#"
Expand Down Expand Up @@ -1438,12 +1426,7 @@ extension_trait! {
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool,
{
AnyFuture {
stream: self,
result: false, // the default if the empty stream
_marker: PhantomData,
f,
}
AnyFuture::new(self, f)
}

#[doc = r#"
Expand All @@ -1468,7 +1451,7 @@ extension_trait! {
assert_eq!(sum, 6);

// if we try to use stream again, it won't work. The following line
// gives "error: use of moved value: `stream`
// gives error: use of moved value: `stream`
// assert_eq!(stream.next(), None);

// let's try that again
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/nth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<S: Unpin> Unpin for NthFuture<'_, S> {}

impl<'a, S> NthFuture<'a, S> {
pub(crate) fn new(stream: &'a mut S, n: usize) -> Self {
NthFuture { stream, n }
Self { stream, n }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/partial_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pin_project! {

impl<L: Stream, R: Stream> PartialCmpFuture<L, R> {
pub(super) fn new(l: L, r: R) -> Self {
PartialCmpFuture {
Self {
l: l.fuse(),
r: r.fuse(),
l_cache: None,
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a, S, P> Unpin for PositionFuture<'a, S, P> {}

impl<'a, S, P> PositionFuture<'a, S, P> {
pub(super) fn new(stream: &'a mut S, predicate: P) -> Self {
PositionFuture {
Self {
stream,
predicate,
index: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pin_project! {

impl<S> Skip<S> {
pub(crate) fn new(stream: S, n: usize) -> Self {
Skip { stream, n }
Self { stream, n }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/stream/skip_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pin_project! {

impl<S, P> SkipWhile<S, P> {
pub(crate) fn new(stream: S, predicate: P) -> Self {
SkipWhile {
Self {
stream,
predicate: Some(predicate),
}
Expand Down
Loading