Skip to content

chore: reduce dependency to pin-utils #2929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ slab = { version = "0.4.2", default-features = false, optional = true }
memchr = { version = "2.2", optional = true }
futures_01 = { version = "0.1.25", optional = true, package = "futures" }
tokio-io = { version = "0.1.9", optional = true }
pin-utils = "0.1.0"
pin-project-lite = "0.2.6"
spin = { version = "0.9.8", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::pin::Pin;

use crate::fns::{inspect_fn, into_fn, ok_fn, InspectFn, IntoFn, OkFn};
use crate::future::{assert_future, Either};
use crate::pin_mut;
use crate::stream::assert_stream;
#[cfg(feature = "alloc")]
use futures_core::future::{BoxFuture, LocalBoxFuture};
Expand All @@ -18,7 +19,6 @@ use futures_core::{
stream::Stream,
task::{Context, Poll},
};
use pin_utils::pin_mut;

// Combinators

Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern crate std;

// Macro re-exports
pub use futures_core::ready;
pub use pin_utils::pin_mut;

#[cfg(feature = "async-await")]
#[macro_use]
Expand All @@ -33,7 +32,6 @@ mod async_await;
pub use self::async_await::*;

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

#[cfg(feature = "async-await")]
pub mod async_await {
pub use crate::async_await::*;
}
Expand Down Expand Up @@ -328,4 +327,5 @@ pub mod lock;
mod abortable;

mod fns;
mod macros;
mod unfold_state;
31 changes: 31 additions & 0 deletions futures-util/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Pins a value on the stack.
///
/// Can safely pin values that are not `Unpin` by taking ownership.
///
/// **Note:** Since Rust 1.68, this macro is soft-deprecated in favor of
/// [`pin!`](https://doc.rust-lang.org/std/pin/macro.pin.html) macro
/// in the standard library.
///
/// # Example
///
/// ```rust
/// # use futures_util::pin_mut;
/// # use core::pin::Pin;
/// # struct Foo {}
/// let foo = Foo { /* ... */ };
/// pin_mut!(foo);
/// let _: Pin<&mut Foo> = foo;
/// ```
#[macro_export]
macro_rules! pin_mut {
($($x:ident),* $(,)?) => { $(
// Move the value to ensure that it is owned
let mut $x = $x;
// Shadow the original binding so that it can't be directly accessed
// ever again.
#[allow(unused_mut)]
let mut $x = unsafe {
$crate::__private::Pin::new_unchecked(&mut $x)
};
)* }
}