Comments (2)
For example, for a time I thought I understood pinning and then I saw the implementation of futures::executor::block_on()
:
pub fn block_on<F: Future>(f: F) -> F::Output {
pin_mut!(f);
run_executor(|cx| f.as_mut().poll(cx))
}
That pin_mut!
macro turns out to be critical—the function doesn't compile without it. Yet I'm completely baffled by it and would never have considered that something like it might be necessary from reading the pinning chapter.
Reading up on pin_mut!
and its implementation was not helpful in illustrating exactly what is going on:
/// Pins a value on the stack.
///
/// ```
/// # use pin_utils::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::core_reexport::pin::Pin::new_unchecked(&mut $x)
};
)* }
}
I know there is an underlying logic here and I feel like a diagram might be helpful to understanding.
from async-book.
Hm, what kind of a diagram did you have in mind? The key bit is just that the pinned value stays in the same place-- it doesn't really matter where it, or anything else for that matter, is.
from async-book.
Related Issues (20)
- Example of moving Pin is confusing HOT 3
- What is the current status of this book? HOT 3
- This book tastes phoney. HOT 3
- Unnecessary import of Unpin
- May be adding more details about Executor's run method
- Confused about `async` after read 2.3
- A
- Simpler future lifecycle HOT 2
- `.await` explanation
- Thoughts on making the philipp oppermann's 'async/await' blog a part of the official rust documentation.
- Shouldn't this comma be missing? HOT 1
- Include info about std’s `pin` macro when talking about stack pinning
- Why do we manually implement Unpin for MockTcpStream if the Unpin trait is automically implemented for it?
- "Under the Hood" chapter doesn't have any `block_on`
- The formatting issue with the Future Trait chapter
- async-std is used but installation not mentioned
- add 中文 (zh_CN) translate version
- Update src/04_pinning/01_chapter.md HOT 4
- Async zero-cost claim
- Is block_on an executor? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-book.