Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Remember,

    std::result::Result<T, E>
does not restrict

    E: std::error:Err
Whereas the article doesn't say that this is the case, but it mentioned it in a way that confused me: https://www.shuttle.rs/blog/2022/06/30/error-handling#:~:tex....


This is a general principal in the Rust standard library, but it is confusing at first. Similarly you can construct a HashMap without restriction but calling `.get` on it requires the key to implement Hash.

I'll let someone else clarify the reasoning because I'm not confident I remember it correctly. I though this was in the Rust API guidelines but I can't find it after a quick skin.


I couldn't find it in the API guidelines either. From what I understand, the idea is that any trait bounds, which includes generic type parameter bounds and lifetime bound on a type (struct or enum) would be repeated back in the impl block

there is a nice discussion on this issue here: https://github.com/rust-lang/rust-clippy/issues/1689




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: