amount: Improve docs on div by weight

Make an effort to improve the docs on `Amount::checked_div_by_weight`
and `ops::Div<weight> for Amount`.
This commit is contained in:
Tobin C. Harding 2024-10-31 12:09:41 +11:00
parent 2b4a61739a
commit 41c80cc476
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 5 additions and 1 deletions

View File

@ -235,7 +235,7 @@ impl Amount {
///
/// Be aware that integer division loses the remainder if no exact division
/// can be made. This method rounds up ensuring the transaction fee-rate is
/// sufficient. If you wish to round-down, use the unchecked version instead.
/// sufficient. If you wish to round down use `amount / weight`.
///
/// [`None`] is returned if an overflow occurred.
#[cfg(feature = "alloc")]

View File

@ -211,6 +211,10 @@ impl Mul<Weight> for FeeRate {
impl Div<Weight> for Amount {
type Output = FeeRate;
/// Truncating integer division.
///
/// This is likely the wrong thing for a user dividing an amount by a weight. Consider using
/// `checked_div_by_weight` instead.
fn div(self, rhs: Weight) -> Self::Output { FeeRate(self.to_sat() * 1000 / rhs.to_wu()) }
}