Skip to content

Commit

Permalink
breaking: Import ready and pending from libstd
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed Aug 17, 2023
1 parent d6a3bdc commit e19ced4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
matrix:
# When updating this, the reminder to update the minimum supported
# Rust version in Cargo.toml.
rust: ['1.40']
rust: ['1.48']
steps:
- uses: actions/checkout@v3
- name: Install Rust
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Contributors to futures-rs",
]
edition = "2018"
rust-version = "1.40"
rust-version = "1.48"
description = "Futures, streams, and async I/O combinators"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/smol-rs/futures-lite"
Expand Down
73 changes: 1 addition & 72 deletions src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
extern crate alloc;

#[doc(no_inline)]
pub use core::future::Future;
pub use core::future::{pending, ready, Future, Pending, Ready};

use core::fmt;
use core::marker::PhantomData;
use core::pin::Pin;

use pin_project_lite::pin_project;
Expand Down Expand Up @@ -110,46 +109,6 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
})
}

/// Creates a future that is always pending.
///
/// # Examples
///
/// ```no_run
/// use futures_lite::future;
///
/// # spin_on::spin_on(async {
/// future::pending::<()>().await;
/// unreachable!();
/// # })
/// ```
pub fn pending<T>() -> Pending<T> {
Pending {
_marker: PhantomData,
}
}

/// Future for the [`pending()`] function.
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Pending<T> {
_marker: PhantomData<T>,
}

impl<T> Unpin for Pending<T> {}

impl<T> fmt::Debug for Pending<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Pending").finish()
}
}

impl<T> Future for Pending<T> {
type Output = T;

fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> {
Poll::Pending
}
}

/// Polls a future just once and returns an [`Option`] with the result.
///
/// # Examples
Expand Down Expand Up @@ -247,36 +206,6 @@ where
}
}

/// Creates a future that resolves to the provided value.
///
/// # Examples
///
/// ```
/// use futures_lite::future;
///
/// # spin_on::spin_on(async {
/// assert_eq!(future::ready(7).await, 7);
/// # })
/// ```
pub fn ready<T>(val: T) -> Ready<T> {
Ready(Some(val))
}

/// Future for the [`ready()`] function.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Ready<T>(Option<T>);

impl<T> Unpin for Ready<T> {}

impl<T> Future for Ready<T> {
type Output = T;

fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
Poll::Ready(self.0.take().expect("`Ready` polled after completion"))
}
}

/// Wakes the current task and returns [`Poll::Pending`] once.
///
/// This function is useful when we want to cooperatively give time to the task scheduler. It is
Expand Down

0 comments on commit e19ced4

Please sign in to comment.