Skip to content

Commit 9c206fe

Browse files
committed
chore: reduce dependency to pin-utils
Signed-off-by: tison <wander4096@gmail.com>
1 parent 3a80c14 commit 9c206fe

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

futures-util/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ slab = { version = "0.4.2", default-features = false, optional = true }
4141
memchr = { version = "2.2", optional = true }
4242
futures_01 = { version = "0.1.25", optional = true, package = "futures" }
4343
tokio-io = { version = "0.1.9", optional = true }
44-
pin-utils = "0.1.0"
4544
pin-project-lite = "0.2.6"
4645
spin = { version = "0.9.8", optional = true }
4746

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

+30-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use futures_core::{
1818
stream::Stream,
1919
task::{Context, Poll},
2020
};
21-
use pin_utils::pin_mut;
2221

2322
// Combinators
2423

@@ -112,6 +111,36 @@ mod shared;
112111
#[cfg(any(feature = "std", all(feature = "alloc", feature = "spin")))]
113112
pub use self::shared::{Shared, WeakShared};
114113

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+
::std::pin::Pin::new_unchecked(&mut $x)
140+
};
141+
)* }
142+
}
143+
115144
impl<T: ?Sized> FutureExt for T where T: Future {}
116145

117146
/// 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
@@ -23,7 +23,6 @@ extern crate std;
2323

2424
// Macro re-exports
2525
pub use futures_core::ready;
26-
pub use pin_utils::pin_mut;
2726

2827
#[cfg(feature = "async-await")]
2928
#[macro_use]

0 commit comments

Comments
 (0)