Reduce amount of unwraps
Created by: hcpl
Things have done to achieve that:
- Introducing an
error_chain-ish custom error type, convertable from all other ones used in src/event.rs and src/cursor.rs.
.unwrap()s in src/event.rs and src/cursor.rs by explicit error return values.
- Modifying public interfaces which is mentioned below.
- Refactoring and fixing formatting.
Changes that can be considered as regressions:
- Using custom error type instead of
std::io::Errormay add memory and likely but little CPU overhead, though compiler could possibly pull some null-pointer optimizations to completely remove the said overhead. This is also useful for end-users that want to filter the specific error which is hard with
io::Error::new(/* whatever io::ErrorKind variant here */, "custom error message").
- Breaking changes in the public
cursor_posmethod now returns
error::Result<(u16, u16)>instead of
Possible improvement ideas, their pros and cons:
- Switch completely to
error_chain- this introduces the
backtracedependency which may not be suitable for platforms that don't support it, and as a result, makes the
error::Errortype consume more memory - which was the primary reason to not to use that crate from the beginning. On the other hand, improved maintainability and readability.
- If the breaking change above is accepted, use
error::Resultthroughout the crate, not just in
src/cursor.rs, for better interoperability and consistency (if make a breaking change anyway, do it correctly). If not, then convert everything back to
io::Resultwhich is fine, but in this case custom errors do need heap allocation. And of course, no plans to go back to
.unwrap()s (the fewer unexpected panics, the better).