| ▲ | Four Months of Zig(gracefulliberty.com) | ||||||||||||||||
| 20 points by ibobev 2 hours ago | 7 comments | |||||||||||||||||
| ▲ | paaloeye 6 minutes ago | parent | next [-] | ||||||||||||||||
Does ReTangled have anything to do with https://tangled.org? | |||||||||||||||||
| ▲ | LoganDark 39 minutes ago | parent | prev | next [-] | ||||||||||||||||
> In Rust you can use ?, which is quicker than unwrap, but you also have to do something like Result<Type, Box<dyn std::error::Error> No, you don't! When returning Result<T, E>, you can use ? on any Result<T2, E2> where E: From<E2>. In other words E doesn't have to be Box<dyn>, it just has to satisfy From<E2>. Crates like thiserror make it easy to define your own error types that can be easily converted from all the other error types you can encounter in your functions! I do this whenever it doesn't make sense to use an inner error type directly, or whenever a function does its own validation that deserves its own error variant. On top of that, I tend to also have error variants for each place in the function rather than only for each type of inner error. At error sites I do something like `.map_err(MyError::PlaceInTheFunction)?` rather than only `?`, and then errors become like a very efficient backtrace :) | |||||||||||||||||
| |||||||||||||||||
| ▲ | paaloeye an hour ago | parent | prev [-] | ||||||||||||||||
$curl: (6) Could not resolve host: gracefulliberty.com HN effect? | |||||||||||||||||
| |||||||||||||||||