Redefine 'try' macro to omit From::from error conversion

This commit is contained in:
David Tolnay 2022-09-21 21:36:44 -07:00
parent a9320db6f9
commit fa6ce42056
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -249,6 +249,19 @@ mod lib {
pub use self::core::time::Duration;
}
// None of this crate's error handling needs the `From::from` error conversion
// performed implicitly by the `?` operator or the standard library's `try!`
// macro. This simplified macro gives a 5.5% improvement in compile time
// compared to standard `try!`, and 9% improvement compared to `?`.
macro_rules! try {
($expr:expr) => {
match $expr {
Ok(val) => val,
Err(err) => return Err(err),
}
};
}
////////////////////////////////////////////////////////////////////////////////
#[macro_use]