Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8121fb9

Browse files
committed
MaybeDone::new()
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 9161a9d commit 8121fb9

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

src/join.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! join {
2828
$(
2929
// Move future into a local so that it is pinned in one place and
3030
// is no longer accessible by the end user.
31-
let mut $fut = $crate::maybe_done($fut);
31+
let mut $fut = $crate::MaybeDone::new($fut);
3232
)*
3333
$crate::utils::poll_fn(move |cx| {
3434
use $crate::utils::future::Future;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod select;
2828
mod try_join;
2929
mod try_select;
3030

31-
pub use maybe_done::{maybe_done, MaybeDone};
31+
pub use maybe_done::MaybeDone;
3232

3333
/// Helper re-exports for use in macros.
3434
pub mod utils {

src/maybe_done.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ use core::pin::Pin;
1010
use futures_core::ready;
1111
use futures_core::task::{Context, Poll};
1212

13-
/// Create a new instance of `MaybeDone`.
14-
pub fn maybe_done<Fut: Future>(future: Fut) -> MaybeDone<Fut> {
15-
MaybeDone::Future(future)
16-
}
17-
1813
/// A future that may have completed.
1914
#[derive(Debug)]
2015
pub enum MaybeDone<Fut: Future> {
@@ -28,10 +23,16 @@ pub enum MaybeDone<Fut: Future> {
2823
}
2924

3025
impl<Fut: Future> MaybeDone<Fut> {
26+
/// Create a new instance of `MaybeDone`.
27+
pub fn new(future: Fut) -> MaybeDone<Fut> {
28+
Self::Future(future)
29+
}
30+
3131
/// Returns an [`Option`] containing a mutable reference to the output of the future.
3232
/// The output of this method will be [`Some`] if and only if the inner
3333
/// future has been completed and [`take`](MaybeDone::take)
3434
/// has not yet been called.
35+
#[allow(clippy::wrong_self_convention)]
3536
#[inline]
3637
pub fn as_mut(self: Pin<&mut Self>) -> Option<&mut Fut::Output> {
3738
unsafe {
@@ -47,6 +48,7 @@ impl<Fut: Future> MaybeDone<Fut> {
4748
/// The output of this method will be [`Some`] if and only if the inner
4849
/// future has been completed and [`take`](MaybeDone::take)
4950
/// has not yet been called.
51+
#[allow(clippy::wrong_self_convention)]
5052
#[inline]
5153
pub fn as_ref(self: Pin<&Self>) -> Option<&Fut::Output> {
5254
let this = self.get_ref();

src/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! select {
3535
$(
3636
// Move future into a local so that it is pinned in one place and
3737
// is no longer accessible by the end user.
38-
let mut $fut = $crate::maybe_done($fut);
38+
let mut $fut = $crate::MaybeDone::new($fut);
3939
)*
4040
$crate::utils::poll_fn(move |cx| {
4141
use $crate::utils::future::Future;

src/try_join.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ macro_rules! try_join {
5252
$(
5353
// Move future into a local so that it is pinned in one place and
5454
// is no longer accessible by the end user.
55-
let mut $fut = $crate::maybe_done($fut);
55+
let mut $fut = $crate::MaybeDone::new($fut);
5656
)*
5757

5858
let res: Result<_, _> = poll_fn(move |cx| {

src/try_select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
///
77
/// `try_select!` is similar to [`select!`], but keeps going if a future
88
/// resolved to an error until all futures have been resolved. In which case
9-
/// the last error found will be returned.
9+
/// the error of the last item in the list will be returned.
1010
///
1111
/// This macro is only usable inside of async functions, closures, and blocks.
1212
///
@@ -42,7 +42,7 @@ macro_rules! try_select {
4242
$(
4343
// Move future into a local so that it is pinned in one place and
4444
// is no longer accessible by the end user.
45-
let mut $fut = $crate::maybe_done($fut);
45+
let mut $fut = $crate::MaybeDone::new($fut);
4646
)*
4747

4848
let res: Result<_, _> = poll_fn(move |cx| {

0 commit comments

Comments
 (0)