trait
From — infallible conversion
Implement From<T> on the destination for a meaningful conversion that cannot fail. Rust supplies Into for that pair automatically. Passing an owned non-Copy input consumes it. Expected stdout (not executed): 500 Common mistake: Implementing From for a conversion that can reject input.
Formal Syntax & Structure
rust syntaxrust
fn from(value: T) -> SelfWorking Example
Example Snippetrust
fn main() { let amount = u32::from(500u16); println!("{amount}");}