≈ the.bay.news

Which is more idiomatic

The Rust Programming Language Forum
Which is more idiomatic
Given enum FooError { Bar(BarError), Baz, } enum BarError { A, B, C(String), } impl From<BarError> for FooError { fn from(err: BarError) -> Self { Self::Bar(err) } } which is better fn foo(a: bool, b: u8) -> Result<u8, FooError> { use FooError as E; // ... // #1 if b < 100 { return Err(E::Bar(BarError::A)); } // #2 if b < 100 { return Err(BarError::A.into()); } // #3 if b < 100 { Err(BarError::A)?; } // ... Ok(b) } I have been ...

0 comments

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

No comments yet.