trait
TryFrom — fallible conversion
Use TryFrom for conversions that may reject values. The associated Error describes failure. Unlike a narrowing as cast, the standard integer implementation checks representability. Expected stdout (not executed): true Common mistake: Using unwrap on unvalidated input when conversion failure is expected.
Formal Syntax & Structure
rust syntaxrust
type Error; fn try_from(value: T) -> Result<Self, Self::Error>Working Example
Example Snippetrust
fn main() { println!("{}", u8::try_from(300u16).is_err());}