From a60051c8a20ae61c7f003e6cdcb891e20b210657 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 27 Apr 2021 12:27:23 +1200 Subject: [PATCH] Add from_raw constructors to NoteValue and ValueSum These might be replaced later with APIs that can provide more useful bounds checks, but we do need some way to construct these types. --- src/value.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/value.rs b/src/value.rs index 75fe837c..ce1ae43c 100644 --- a/src/value.rs +++ b/src/value.rs @@ -52,6 +52,14 @@ impl NoteValue { Default::default() } + /// Creates a note value from its raw numeric value. + /// + /// This only enforces that the value is an unsigned 64-bit integer. Callers should + /// enforce any additional constraints on the value's valid range themselves. + pub fn from_raw(value: u64) -> Self { + NoteValue(value) + } + pub(crate) fn to_le_bits(self) -> BitArray { BitArray::::new(self.0.to_le_bytes()) } @@ -71,6 +79,16 @@ impl Sub for NoteValue { #[derive(Clone, Copy, Debug, Default)] pub struct ValueSum(i64); +impl ValueSum { + /// Creates a value sum from its raw numeric value. + /// + /// This only enforces that the value is a signed 63-bit integer. Callers should + /// enforce any additional constraints on the value's valid range themselves. + pub fn from_raw(value: i64) -> Self { + ValueSum(value) + } +} + impl Add for ValueSum { type Output = Result;