From 41c80cc476477facf028bda566465c61a8256d7e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 31 Oct 2024 12:09:41 +1100 Subject: [PATCH] amount: Improve docs on div by weight Make an effort to improve the docs on `Amount::checked_div_by_weight` and `ops::Div for Amount`. --- units/src/amount/unsigned.rs | 2 +- units/src/fee_rate.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs index f2f8153c1..5efefb426 100644 --- a/units/src/amount/unsigned.rs +++ b/units/src/amount/unsigned.rs @@ -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")] diff --git a/units/src/fee_rate.rs b/units/src/fee_rate.rs index 237de0f5b..b3974422c 100644 --- a/units/src/fee_rate.rs +++ b/units/src/fee_rate.rs @@ -211,6 +211,10 @@ impl Mul for FeeRate { impl Div 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()) } }