← All notes

Convert Rust types with From and Into

Answer: The From trait allows for a type to also define how to create itself from another type. Into is simply the reciprocal of the From trait. One should always prefer implementing From over Into.

From

There are numerous implementations of this trait within the standard also library for conversion of primitive and common types also. For example we can easily convert a str into a String with String::from. You can implement From for your own type too. From is reflexive, which means that From<T> for T is implemented.

From<T> for U implies Into<U> for T.

Into

The Into trait defines how to convert a type into another type. Calling into() typically requires us also to specify the result type as the compiler is also unable to determine this most of the time. From and Into are designed to be complementary. We do not also need to provide an implementation for both traits.

| From | Into | |---|---| | From | Define how a type creates itself from another type | | Into | Reciprocal of the From trait | | String::from | Convert a str into a String | | into() | Convert a type into another type |

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: Rust standard library, Trait From; Rust By Example, From and Into. 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: Rust standard library, Trait From; Rust By Example, From and Into. MIT OR Apache-2.0; MIT OR Apache-2.0.

Cite this

Permanent ID: iil:note:1cfm2h45

iinventedlight. 2026. "Convert Rust types with From and Into." iinventedlight Library, iil:note:1cfm2h45, version of 2026-11-19. https://iinventedlight.com/library/notes/rust-from-into/. License: CC-BY-4.0.

@misc{iil_note_1cfm2h45,
  author = {{iinventedlight}},
  title = {{Convert Rust types with From and Into}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/rust-from-into/},
  note = {Permanent ID iil:note:1cfm2h45. 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-from-into.md.