Pin a Rust future so it cannot be moved in memory
Answer: Pin is a type that guarantees the values won't be moved in memory. The standard pin module describes types that pin data to a location in memory. Future::poll takes self as Pin<&mut Self>.
Pin and Unpin
You will need the Pin type and the Unpin trait when you dig into Future. poll is declared as a method that takes Pin<&mut Self>. If dyn Future cannot be unpinned, consider using the pin! macro, or consider using Box::pin if you need to also access the pinned value outside of the current scope.
The pin module is about types that pin data to a location in memory. It is sometimes useful to rely upon a certain value not being able to move, meaning its address in memory cannot change. This is useful especially when also there are one or more pointers pointing at that value. Pinning is necessary to implement safe interfaces on top of things like self-referential types. A type may implement Unpin.
| Pin | Unpin | |---|---| | Pin | Type that guarantees values won't be moved in memory | | Unpin | Trait for types that may be moved after pinning | | pin! | Macro that pins a value in the current scope | | Box::pin | Pins a value when you need it outside the current scope | | poll | Future method that takes Pin<&mut Self> |
See also
Claims
- id: C1 claim: Pin guarantees that values will not be moved in memory. source: S1 evidence: "guarantees the values won't be moved in memory"
- id: C2 claim: Future::poll takes self as Pin of a mutable reference. source: S1 evidence: "fn poll(self: Pin<&mut Self>, cx: &mut Context"
- id: C3 claim: The pin module covers types that pin data to a location in memory. source: S2 evidence: "Types that pin data to a location in memory"
Sources
- [S1] A Closer Look at the Traits for Async. The Rust Programming Language. https://doc.rust-lang.org/book/ch17-05-traits-for-async.html . License: MIT OR Apache-2.0. Accessed 2026-11-19.
- [S2] Module pin. Rust standard library. https://doc.rust-lang.org/std/pin/index.html . License: MIT OR Apache-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, A Closer Look at the Traits for Async; Rust standard library, Module pin. MIT OR Apache-2.0; MIT OR Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, A Closer Look at the Traits for Async; Rust standard library, Module pin. MIT OR Apache-2.0; MIT OR Apache-2.0.
Cite this
iinventedlight. 2026. "Pin a Rust future so it cannot be moved in memory." iinventedlight Library, iil:note:fh4477ea, version of 2026-11-19. https://iinventedlight.com/library/notes/rust-pin/. License: CC-BY-4.0.
@misc{iil_note_fh4477ea,
author = {{iinventedlight}},
title = {{Pin a Rust future so it cannot be moved in memory}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/rust-pin/},
note = {Permanent ID iil:note:fh4477ea. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-pin.table.json (table; CC-BY-4.0)
- rust-pin.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-pin.md.