Skip to content

Commit 59fdb4c

Browse files
Core cleanup
1 parent ba4ec7f commit 59fdb4c

File tree

27 files changed

+278
-262
lines changed

27 files changed

+278
-262
lines changed
Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
//! Futures.
22
33
use crate::task::{self, Poll};
4-
use core::marker::Unpin;
54
use core::mem::PinMut;
6-
pub use core::future::{Future, FutureObj, LocalFutureObj, UnsafeFutureObj};
7-
8-
mod option;
9-
pub use self::option::FutureOption;
10-
11-
#[cfg(feature = "either")]
12-
mod either;
13-
14-
/// Will probably merge with futures_util::FutureExt
15-
pub trait CoreFutureExt: Future {
16-
/// A convenience for calling `Future::poll` on `Unpin` future types.
17-
fn poll_unpin(&mut self, cx: &mut task::Context) -> Poll<Self::Output>
18-
where Self: Unpin + Sized
19-
{
20-
PinMut::new(self).poll(cx)
21-
}
22-
}
235

24-
impl<T: ?Sized> CoreFutureExt for T where T: Future {}
6+
pub use core::future::{Future, FutureObj, LocalFutureObj, UnsafeFutureObj};
257

268
/// A convenience for futures that return `Result` values that includes
279
/// a variety of adapters tailored to such futures.
@@ -54,24 +36,3 @@ impl<F, T, E> TryFuture for F
5436
self.poll(cx)
5537
}
5638
}
57-
58-
/// A future that is immediately ready with a value
59-
#[derive(Debug, Clone)]
60-
#[must_use = "futures do nothing unless polled"]
61-
pub struct ReadyFuture<T>(Option<T>);
62-
63-
impl<T> Unpin for ReadyFuture<T> {}
64-
65-
impl<T> Future for ReadyFuture<T> {
66-
type Output = T;
67-
68-
#[inline]
69-
fn poll(mut self: PinMut<Self>, _cx: &mut task::Context) -> Poll<T> {
70-
Poll::Ready(self.0.take().unwrap())
71-
}
72-
}
73-
74-
/// Create a future that is immediately ready with a value.
75-
pub fn ready<T>(t: T) -> ReadyFuture<T> {
76-
ReadyFuture(Some(t))
77-
}

futures-core/src/future/either.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

futures-core/src/future/option.rs

Lines changed: 0 additions & 35 deletions
This file was deleted.

futures-core/src/lib.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@
1111

1212
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]
1313

14-
#[macro_use]
1514
#[cfg(feature = "std")]
1615
extern crate std;
16+
1717
#[cfg(feature = "either")]
1818
extern crate either;
1919

20-
#[doc(hidden)]
21-
pub mod core_reexport {
22-
pub use core::{mem, future, task};
23-
}
24-
2520
#[doc(hidden)] pub use crate::future::Future;
26-
#[doc(hidden)] pub use crate::future::CoreFutureExt;
2721
#[doc(hidden)] pub use crate::future::TryFuture;
2822

2923
#[doc(hidden)] pub use crate::stream::Stream;
@@ -38,9 +32,6 @@ macro_rules! if_std {
3832
)*)
3933
}
4034

41-
#[macro_use]
42-
mod macros;
43-
4435
pub mod future;
4536

4637
pub mod stream;

futures-core/src/macros/poll.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

futures-core/src/stream/mod.rs renamed to futures-core/src/stream.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use crate::task::{self, Poll};
44
use core::marker::Unpin;
55
use core::mem::PinMut;
66

7+
#[cfg(feature = "either")]
8+
use either::Either;
9+
710
/// A stream of values produced asynchronously.
811
///
912
/// If `Future<Output = T>` is an asynchronous version of `T`, then `Stream<Item
@@ -80,6 +83,23 @@ impl<'a, S: ?Sized + Stream> Stream for PinMut<'a, S> {
8083
}
8184
}
8285

86+
#[cfg(feature = "either")]
87+
impl<A, B> Stream for Either<A, B>
88+
where A: Stream,
89+
B: Stream<Item = A::Item>
90+
{
91+
type Item = A::Item;
92+
93+
fn poll_next(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Option<A::Item>> {
94+
unsafe {
95+
match PinMut::get_mut_unchecked(self) {
96+
Either::Left(a) => PinMut::new_unchecked(a).poll_next(cx),
97+
Either::Right(b) => PinMut::new_unchecked(b).poll_next(cx),
98+
}
99+
}
100+
}
101+
}
102+
83103
/// A convenience for streams that return `Result` values that includes
84104
/// a variety of adapters tailored to such futures.
85105
pub trait TryStream {

futures-core/src/task.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Task notification.
2+
3+
pub use core::task::{
4+
Context, Poll, Executor,
5+
Waker, LocalWaker, UnsafeWake,
6+
SpawnErrorKind, SpawnObjError, SpawnLocalObjError,
7+
};
8+
9+
if_std! {
10+
pub use std::task::{Wake, local_waker, local_waker_from_nonlocal};
11+
}

futures-core/src/task/mod.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

futures-executor/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#[macro_use]
1414
extern crate std;
1515

16-
#[cfg_attr(feature = "std", macro_use)]
17-
extern crate futures_core;
16+
#[cfg(feature = "std")]
17+
#[macro_use]
18+
extern crate futures_util;
1819

1920
macro_rules! if_std {
2021
($($i:item)*) => ($(

futures-executor/src/spawn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use futures_core::future::{Future, CoreFutureExt};
2-
use futures_core::task::{self, Poll, ContextExt};
1+
use futures_core::future::Future;
2+
use futures_core::task::{self, Poll};
33
use futures_channel::oneshot::{channel, Sender, Receiver};
4-
use futures_util::FutureExt;
5-
4+
use futures_util::future::FutureExt;
5+
use futures_util::task::ContextExt;
66
use std::thread;
77
use std::sync::Arc;
88
use std::sync::atomic::Ordering;

futures-executor/src/thread_pool.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
use std::prelude::v1::*;
2-
1+
use crate::enter;
2+
use crate::unpark_mutex::UnparkMutex;
3+
use futures_core::future::{Future, FutureObj};
4+
use futures_core::task::{self, Poll, Wake, Executor, SpawnObjError};
5+
use futures_util::future::FutureExt;
6+
use num_cpus;
37
use std::io;
8+
use std::prelude::v1::*;
49
use std::sync::{Arc, Mutex};
510
use std::sync::atomic::{AtomicUsize, Ordering};
611
use std::sync::mpsc;
712
use std::thread;
813
use std::fmt;
914

10-
use futures_core::future::{Future, FutureObj, CoreFutureExt};
11-
use futures_core::task::{self, Poll, Wake, Executor, SpawnObjError};
12-
13-
use crate::enter;
14-
use num_cpus;
15-
use crate::unpark_mutex::UnparkMutex;
16-
1715
/// A general-purpose thread pool for scheduling asynchronous tasks.
1816
///
1917
/// The thread pool multiplexes any number of tasks onto a fixed number of

futures-util/src/future/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
//! This module contains a number of functions for working with `Future`s,
44
//! including the `FutureExt` trait which adds methods to `Future` types.
55
6+
use core::marker::Unpin;
7+
use core::mem::PinMut;
68
use futures_core::future::Future;
79
use futures_core::stream::Stream;
8-
use futures_core::task::Executor;
10+
use futures_core::task::{self, Poll, Executor};
911

1012
// Primitive futures
1113
mod empty;
@@ -17,9 +19,15 @@ pub use self::lazy::{lazy, Lazy};
1719
mod maybe_done;
1820
pub use self::maybe_done::{maybe_done, MaybeDone};
1921

22+
mod option;
23+
pub use self::option::{OptionFuture};
24+
2025
mod poll_fn;
2126
pub use self::poll_fn::{poll_fn, PollFn};
2227

28+
mod ready;
29+
pub use self::ready::{ready, Ready};
30+
2331
// Combinators
2432
mod flatten;
2533
pub use self::flatten::Flatten;
@@ -506,14 +514,14 @@ pub trait FutureExt: Future {
506514
/// ```rust
507515
/// # extern crate futures;
508516
/// use futures::prelude::*;
509-
/// use futures::future::{self, ReadyFuture};
517+
/// use futures::future::{self, Ready};
510518
/// use futures::executor::block_on;
511519
///
512520
/// # fn main() {
513521
/// let mut future = future::ready(2);
514522
/// assert!(block_on(future.catch_unwind()).is_ok());
515523
///
516-
/// let mut future = future::lazy(|_| -> ReadyFuture<i32> {
524+
/// let mut future = future::lazy(|_| -> Ready<i32> {
517525
/// panic!();
518526
/// future::ready(2)
519527
/// });
@@ -606,6 +614,13 @@ pub trait FutureExt: Future {
606614
{
607615
WithExecutor::new(self, executor)
608616
}
617+
618+
/// A convenience for calling `Future::poll` on `Unpin` future types.
619+
fn poll_unpin(&mut self, cx: &mut task::Context) -> Poll<Self::Output>
620+
where Self: Unpin + Sized
621+
{
622+
PinMut::new(self).poll(cx)
623+
}
609624
}
610625

611626
// Just a helper function to ensure the futures we're returning all have the

0 commit comments

Comments
 (0)