-
-
Save benluelo/aa63c166398f5f74b123081ed7da7e58 to your computer and use it in GitHub Desktop.
Workaround for https://github.com/rust-lang/rust/issues/74935 to reduce the boilerplate of manual match statements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `?` is still unstable in const contexts :( | |
macro_rules! option_try { | |
($($opt:tt)+) => { | |
match $($opt)+ { | |
Some(t) => t, | |
None => return None, | |
} | |
}; | |
} | |
impl Weight { | |
/// Checked [`Weight`] addition. Computes `self + rhs`, returning `None` if overflow occurred. | |
pub const fn checked_add(&self, rhs: &Self) -> Option<Self> { | |
Some(Self { | |
ref_time: option_try!(self.ref_time.checked_add(rhs.ref_time)), | |
proof_size: option_try!(self.proof_size.checked_add(rhs.proof_size)), | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment