Debian Codegraph @

debian/rust-vendor/futures-util/src/macros.rs

raw
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 }