From eae4ac41104efa7d04ac0b9874a40f0d4826033b Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 14 Sep 2021 20:45:47 +0100 Subject: [PATCH] `impl memuse::DynamicUsage for Amount` Required to use `DynamicUsage` with `orchard::Bundle<_, Amount>`. --- zcash_primitives/CHANGELOG.md | 2 ++ zcash_primitives/Cargo.toml | 1 + .../src/transaction/components/amount.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+) diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index 8a1306968..bc0d56e7d 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -51,6 +51,8 @@ and this library adheres to Rust's notion of data, as described above. - `zcash_primitives::serialize` has been factored out as a new `zcash_encoding` crate, which can be found in the `components` directory. +- `zcash_primitives::transaction::components::Amount` now implements + `memuse::DynamicUsage`, to enable `orchard::Bundle<_, Amount>::dynamic_usage`. ### Changed - MSRV is now 1.51.0. diff --git a/zcash_primitives/Cargo.toml b/zcash_primitives/Cargo.toml index 00cfc6271..bafb6f900 100644 --- a/zcash_primitives/Cargo.toml +++ b/zcash_primitives/Cargo.toml @@ -33,6 +33,7 @@ incrementalmerkletree = "0.1" jubjub = "0.8" lazy_static = "1" log = "0.4" +memuse = "0.2" nonempty = "0.7" orchard = "0.0" pasta_curves = "0.2" diff --git a/zcash_primitives/src/transaction/components/amount.rs b/zcash_primitives/src/transaction/components/amount.rs index 601d29132..4b20a1cb1 100644 --- a/zcash_primitives/src/transaction/components/amount.rs +++ b/zcash_primitives/src/transaction/components/amount.rs @@ -23,6 +23,18 @@ pub const DEFAULT_FEE: Amount = Amount(1000); #[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord)] pub struct Amount(i64); +impl memuse::DynamicUsage for Amount { + #[inline(always)] + fn dynamic_usage(&self) -> usize { + 0 + } + + #[inline(always)] + fn dynamic_usage_bounds(&self) -> (usize, Option) { + (0, Some(0)) + } +} + impl Amount { /// Returns a zero-valued Amount. pub const fn zero() -> Self {