5 ms·
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 i
by WirelessGigabit 3y ago
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#:~:text=The%20Error%20trait%20is%20defined%20in%20the%20standard%20library.%20It%20basically%20represents%20the%20expectations%20of%20error%20values%20%2D%20values%20of%20type%20E%20in%20Result%3CT%2CE%3E https://www.shuttle.rs/blog/2022/06/30/error-handling#:~:tex....
- iudqnolq 3y agoThis 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.
- zamio 3y agoI 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 https://github.com/rust-lang/rust-clippy/issues/1689