Skip to content

Commit

Permalink
Merge pull request #2281 from dtolnay/try
Browse files Browse the repository at this point in the history
Redefine `try` macro to omit From::from error conversion
  • Loading branch information
dtolnay committed Sep 22, 2022
2 parents a9320db + fa6ce42 commit f0346ae
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions serde/src/lib.rs
Expand Up @@ -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]
Expand Down

0 comments on commit f0346ae

Please sign in to comment.