From da23d16019f4cf926349d9b45a2a6541db77733e Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 4 Feb 2020 17:59:22 +0900 Subject: [PATCH 1/4] feat: to no_std future::pending --- src/future/pending.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/future/pending.rs b/src/future/pending.rs index 968972b51..f3a3379dc 100644 --- a/src/future/pending.rs +++ b/src/future/pending.rs @@ -1,6 +1,6 @@ -use std::future::Future; -use std::marker::PhantomData; -use std::pin::Pin; +use core::future::Future; +use core::marker::PhantomData; +use core::pin::Pin; use crate::task::{Context, Poll}; @@ -24,14 +24,17 @@ use crate::task::{Context, Poll}; /// # /// # }) /// ``` -pub async fn pending() -> T { - let fut = Pending { +pub fn pending() -> Pending { + Pending { _marker: PhantomData, - }; - fut.await + } } -struct Pending { +/// This future is constructed by the [`pending`] function. +/// +/// [`pending`]: fn.pending.html +#[derive(Debug)] +pub struct Pending { _marker: PhantomData, } From 94a6ff34c2d49f74da21dd43187ed4f18efd84b7 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 4 Feb 2020 18:00:44 +0900 Subject: [PATCH 2/4] feat: no to_std future::poll_fn --- src/future/poll_fn.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs index 194526400..1524d27c3 100644 --- a/src/future/poll_fn.rs +++ b/src/future/poll_fn.rs @@ -1,5 +1,5 @@ -use std::pin::Pin; -use std::future::Future; +use core::future::Future; +use core::pin::Pin; use crate::task::{Context, Poll}; @@ -23,15 +23,18 @@ use crate::task::{Context, Poll}; /// # /// # }) /// ``` -pub async fn poll_fn(f: F) -> T +pub fn poll_fn(f: F) -> PollFn where F: FnMut(&mut Context<'_>) -> Poll, { - let fut = PollFn { f }; - fut.await + PollFn { f } } -struct PollFn { +/// This future is constructed by the [`poll_fn`] function. +/// +/// [`poll_fn`]: fn.poll_fn.html +#[derive(Debug)] +pub struct PollFn { f: F, } From 3b9c7f095840d3d7409ea860d184cab9bd7352e4 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 4 Feb 2020 18:01:50 +0900 Subject: [PATCH 3/4] feat: to no_std future::ready --- src/future/ready.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/future/ready.rs b/src/future/ready.rs index 65cba563d..0b7987362 100644 --- a/src/future/ready.rs +++ b/src/future/ready.rs @@ -1,3 +1,8 @@ +use core::future::Future; +use core::pin::Pin; + +use crate::task::{Context, Poll}; + /// Resolves to the provided value. /// /// This function is an async version of [`std::convert::identity`]. @@ -15,6 +20,22 @@ /// # /// # }) /// ``` -pub async fn ready(val: T) -> T { - val +pub fn ready(val: T) -> Ready { + Ready(Some(val)) +} + +/// This future is constructed by the [`ready`] function. +/// +/// [`ready`]: fn.ready.html +#[derive(Debug)] +pub struct Ready(Option); + +impl Unpin for Ready {} + +impl Future for Ready { + type Output = T; + + fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Ready(self.0.take().unwrap()) + } } From 3883079fa586e77b8e31b2fb4c94ef852890350b Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 4 Feb 2020 18:04:31 +0900 Subject: [PATCH 4/4] feat: to no_std future module --- src/future/mod.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/future/mod.rs b/src/future/mod.rs index 9b75533d3..d918ef083 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -48,17 +48,14 @@ cfg_alloc! { pub use future::Future; - pub(crate) mod future; -} - -cfg_std! { + pub use ready::ready; pub use pending::pending; pub use poll_fn::poll_fn; - pub use ready::ready; + pub(crate) mod future; + mod ready; mod pending; mod poll_fn; - mod ready; } cfg_default! { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy