3 ms·
> What would Rust's "From" look like, for example? Idiomatic Go type-erases error types into `error`, when there is even a known type in the first place. Thus
by masklinn 1y ago
> What would Rust's "From" look like, for example?
Idiomatic Go type-erases error types into `error`, when there is even a known type in the first place.
Thus `From` is not a consideration, because the only `From` you need is
impl<'a, E> From<E> for Box<dyn Error + 'a>
where
E: Error + 'a,
and that means you can just build that in and nothing else (and it's really already built-in by the implicit upcasting of values into interfaces).
- 9rx 1y ago> Go type-erases error types That's clearly not true. type MyError struct{} func (MyError) Error() string { return "MyError" } func main() { var err error = MyError{} fmt.Printf("%T\n", err) // Output: main.MyError } The idea doesn't even make any sense. How could you even begin to handle errors in a meaningful way if you were unable to discern what type the error is?
- deleted 1y ago[deleted]