macros: add pin! macro (#2163)

Used for stack pinning and based on `pin_mut!` from the pin-util crate.

Pinning is used often when working with stream operators and the select!
macro. Given the small size of `pin!` it makes more sense to include a
version than re-export one from a separate crate or require the user to
depend on `pin-util` themselves.
This commit is contained in:
Carl Lerche
2020-01-23 14:40:43 -08:00
committed by GitHub
parent 7079bcd609
commit a70f7203a4
4 changed files with 134 additions and 7 deletions
+12
View File
@@ -0,0 +1,12 @@
use futures::executor::block_on;
async fn my_async_fn() {}
#[test]
fn pin() {
block_on(async {
let future = my_async_fn();
tokio::pin!(future);
(&mut future).await
});
}