← All notes

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

Sources

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

Permanent ID: iil:note:fh4477ea

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.},
}

Markdown

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.

All artifact files (JSON index)

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.