BiagioFesta / wtransport

Async-friendly WebTransport implementation in Rust
Apache License 2.0
346 stars 19 forks source link

Implement Eq, PartialEq, Clone for errors when possible #188

Closed TheButlah closed 1 week ago

TheButlah commented 1 week ago

Overall this should improve the ergonomics of error handling. Eq/PartialEq is very useful for comparing errors with == instead of match statements. And Clone is necessary when needing to store an error (such as from a task), and repeatedly return it to the caller (such as when the struct is now poisoned to due a failed task).

More detail on why I needed this I had a struct that communicated over channels to a tokio task. It would send and receive messages on a wtransport stream. If the task crashed due to a wtransport error, I returned the error via a tokio JoinHandle. In the struct when sending a message, if it detected that the task had died, it would return an error to the caller. I wanted to return the actual real error from wtransport, but that would require me to be able to clone the error each time. Since wtransport didn't support that, I had to use a different less explanatory error instead. You can see my code [here](https://github.com/NexusSocial/nexus-vr/pull/113/files) if you are morbidly curious :)