Merge rust-bitcoin/rust-bitcoin#3608: Mark funtions const
4c94695942
Mark funtions const (yancy) Pull request description: May as well mark these const as well. Follow up to https://github.com/rust-bitcoin/rust-bitcoin/pull/3605 ACKs for top commit: apoelstra: ACK 4c94695942de41e5eca4ac120db2e069c0bb037d; successfully ran local tests; yeah, I think this are all worth consting tcharding: ACK4c94695942
sanket1729: ACK4c94695942
Tree-SHA512: bf41e416cb8a2eb90e26d7bd640df5c2a5a868e3b721bde7cc8a3b97c687bab4d1cb4ab1c4b04ed625e8657e25c59e386720cb0f9d735ffc492e98f5b8b2ca3c
This commit is contained in:
commit
7315ca9a4e
|
@ -105,22 +105,46 @@ impl Weight {
|
|||
/// Checked addition.
|
||||
///
|
||||
/// Computes `self + rhs` returning [`None`] if an overflow occurred.
|
||||
pub fn checked_add(self, rhs: Self) -> Option<Self> { self.0.checked_add(rhs.0).map(Self) }
|
||||
pub const fn checked_add(self, rhs: Self) -> Option<Self> {
|
||||
// No `map()` in const context.
|
||||
match self.0.checked_add(rhs.0) {
|
||||
Some(wu) => Some(Weight::from_wu(wu)),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Checked subtraction.
|
||||
///
|
||||
/// Computes `self - rhs` returning [`None`] if an overflow occurred.
|
||||
pub fn checked_sub(self, rhs: Self) -> Option<Self> { self.0.checked_sub(rhs.0).map(Self) }
|
||||
pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
|
||||
// No `map()` in const context.
|
||||
match self.0.checked_sub(rhs.0) {
|
||||
Some(wu) => Some(Weight::from_wu(wu)),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Checked multiplication.
|
||||
///
|
||||
/// Computes `self * rhs` returning [`None`] if an overflow occurred.
|
||||
pub fn checked_mul(self, rhs: u64) -> Option<Self> { self.0.checked_mul(rhs).map(Self) }
|
||||
pub const fn checked_mul(self, rhs: u64) -> Option<Self> {
|
||||
// No `map()` in const context.
|
||||
match self.0.checked_mul(rhs) {
|
||||
Some(wu) => Some(Weight::from_wu(wu)),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Checked division.
|
||||
///
|
||||
/// Computes `self / rhs` returning [`None`] if `rhs == 0`.
|
||||
pub fn checked_div(self, rhs: u64) -> Option<Self> { self.0.checked_div(rhs).map(Self) }
|
||||
pub const fn checked_div(self, rhs: u64) -> Option<Self> {
|
||||
// No `map()` in const context.
|
||||
match self.0.checked_div(rhs) {
|
||||
Some(wu) => Some(Weight::from_wu(wu)),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Alternative will display the unit.
|
||||
|
|
Loading…
Reference in New Issue