the.bay.news

Safe unions and error types

Rust Internals
Safe unions and error types
Currently there's some workaround to deal with multiple errors types like dyn or anyhow. The idea here is to make the compiler generate this sum type and allow transparent construction and matching. union Error = Utf8Error | ParseIntError; // translates to // enum Error { _anon0(Utf8Error), _anon1(ParseIntError) } fn convert(bytes: &[u8]) -> Result<i32, Error> { let s = std::str::from_utf8(bytes)?; // auto-wraps into Error let n: i32 = s.trim().parse()?; // auto-wraps into Error...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.