Skip to content

Commit cc3a15d

Browse files
authored
chore: remove dependency to pin-utils (#2929)
Signed-off-by: tison <[email protected]>
1 parent 3a80c14 commit cc3a15d

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

futures-util/Cargo.toml

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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};
@@ -18,7 +19,6 @@ use futures_core::{
1819
stream::Stream,
1920
task::{Context, Poll},
2021
};
21-
use pin_utils::pin_mut;
2222

2323
// Combinators
2424

futures-util/src/lib.rs

Lines changed: 2 additions & 2 deletions
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]
@@ -33,7 +32,6 @@ mod async_await;
3332
pub use self::async_await::*;
3433

3534
// Not public API.
36-
#[cfg(feature = "async-await")]
3735
#[doc(hidden)]
3836
pub mod __private {
3937
pub use crate::*;
@@ -43,6 +41,7 @@ pub mod __private {
4341
result::Result::{Err, Ok},
4442
};
4543

44+
#[cfg(feature = "async-await")]
4645
pub mod async_await {
4746
pub use crate::async_await::*;
4847
}
@@ -328,4 +327,5 @@ pub mod lock;
328327
mod abortable;
329328

330329
mod fns;
330+
mod macros;
331331
mod unfold_state;

futures-util/src/macros.rs

Lines changed: 31 additions & 0 deletions
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+
$crate::__private::Pin::new_unchecked(&mut $x)
29+
};
30+
)* }
31+
}

0 commit comments

Comments
 (0)