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
- id: C1 claim: Prefer implementing From over Into because From implies Into. source: S1 evidence: "always prefer implementing From over Into"
- id: C2 claim: From is reflexive, so From for the same type is implemented. source: S1 evidence: "From is reflexive, which means that From<T> for T is implemented"
- id: C3 claim: From lets a type define how to create itself from another type. source: S2 evidence: "define how to create itself from another type"
Sources
- [S1] Trait From. Rust standard library. https://doc.rust-lang.org/std/convert/trait.From.html . License: MIT OR Apache-2.0. Accessed 2026-11-19.
- [S2] From and Into. Rust By Example. https://doc.rust-lang.org/rust-by-example/conversion/from_into.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: 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
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.},
}
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-from-into.table.json (table; CC-BY-4.0)
- rust-from-into.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-from-into.md.