trait
TryInto — fallible target conversion
TryInto is the destination-directed fallible conversion. A TryFrom implementation supplies the matching TryInto implementation. An explicit Result target can resolve type inference. Expected stdout (not executed): Ok(42) Common mistake: Assuming try_into silently truncates when a value does not fit.
Formal Syntax & Structure
rust syntaxrust
type Error; fn try_into(self) -> Result<T, Self::Error>Working Example
Example Snippetrust
fn main() { let byte: Result<u8, _> = 42u16.try_into(); println!("{byte:?}");}