Skip to content

Commit 3629b06

Browse files
committed
address comments
Signed-off-by: tison <[email protected]>
1 parent 6d7ea3e commit 3629b06

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

futures-util/src/future/future/mod.rs

+1-30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use core::pin::Pin;
1010

1111
use crate::fns::{inspect_fn, into_fn, ok_fn, InspectFn, IntoFn, OkFn};
1212
use crate::future::{assert_future, Either};
13+
use crate::pin_mut;
1314
use crate::stream::assert_stream;
1415
#[cfg(feature = "alloc")]
1516
use futures_core::future::{BoxFuture, LocalBoxFuture};
@@ -111,36 +112,6 @@ mod shared;
111112
#[cfg(any(feature = "std", all(feature = "alloc", feature = "spin")))]
112113
pub use self::shared::{Shared, WeakShared};
113114

114-
/// Pins a value on the stack.
115-
///
116-
/// **Note:** Since Rust 1.68, this macro is soft-deprecated in favor of
117-
/// [`pin!`](https://doc.rust-lang.org/std/pin/macro.pin.html) macro
118-
/// in the standard library.
119-
///
120-
/// # Example
121-
///
122-
/// ```rust
123-
/// # use futures_util::pin_mut;
124-
/// # use core::pin::Pin;
125-
/// # struct Foo {}
126-
/// let foo = Foo { /* ... */ };
127-
/// pin_mut!(foo);
128-
/// let _: Pin<&mut Foo> = foo;
129-
/// ```
130-
#[macro_export]
131-
macro_rules! pin_mut {
132-
($($x:ident),* $(,)?) => { $(
133-
// Move the value to ensure that it is owned
134-
let mut $x = $x;
135-
// Shadow the original binding so that it can't be directly accessed
136-
// ever again.
137-
#[allow(unused_mut)]
138-
let mut $x = unsafe {
139-
::core::pin::Pin::new_unchecked(&mut $x)
140-
};
141-
)* }
142-
}
143-
144115
impl<T: ?Sized> FutureExt for T where T: Future {}
145116

146117
/// An extension trait for `Future`s that provides a variety of convenient

futures-util/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,4 @@ mod abortable;
328328

329329
mod fns;
330330
mod unfold_state;
331+
mod macros;

futures-util/src/macros.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// Pins a value on the stack.
2+
///
3+
/// Can safely pin values that are not `Unpin` by taking ownership.
4+
///
5+
/// **Note:** Since Rust 1.68, this macro is soft-deprecated in favor of
6+
/// [`pin!`](https://doc.rust-lang.org/std/pin/macro.pin.html) macro
7+
/// in the standard library.
8+
///
9+
/// # Example
10+
///
11+
/// ```rust
12+
/// # use futures_util::pin_mut;
13+
/// # use core::pin::Pin;
14+
/// # struct Foo {}
15+
/// let foo = Foo { /* ... */ };
16+
/// pin_mut!(foo);
17+
/// let _: Pin<&mut Foo> = foo;
18+
/// ```
19+
#[macro_export]
20+
macro_rules! pin_mut {
21+
($($x:ident),* $(,)?) => { $(
22+
// Move the value to ensure that it is owned
23+
let mut $x = $x;
24+
// Shadow the original binding so that it can't be directly accessed
25+
// ever again.
26+
#[allow(unused_mut)]
27+
let mut $x = unsafe {
28+
::core::pin::Pin::new_unchecked(&mut $x)
29+
};
30+
)* }
31+
}

0 commit comments

Comments
 (0)