Skip to content

Commit fa6ce42

Browse files
committed
Redefine 'try' macro to omit From::from error conversion
1 parent a9320db commit fa6ce42

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

serde/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ mod lib {
249249
pub use self::core::time::Duration;
250250
}
251251

252+
// None of this crate's error handling needs the `From::from` error conversion
253+
// performed implicitly by the `?` operator or the standard library's `try!`
254+
// macro. This simplified macro gives a 5.5% improvement in compile time
255+
// compared to standard `try!`, and 9% improvement compared to `?`.
256+
macro_rules! try {
257+
($expr:expr) => {
258+
match $expr {
259+
Ok(val) => val,
260+
Err(err) => return Err(err),
261+
}
262+
};
263+
}
264+
252265
////////////////////////////////////////////////////////////////////////////////
253266

254267
#[macro_use]

0 commit comments

Comments
 (0)