mirror of https://github.com/zcash/halo2.git
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.
This commit is contained in:
parent
52d87e257c
commit
a60051c8a2
18
src/value.rs
18
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<Lsb0, [u8; 8]> {
|
||||
BitArray::<Lsb0, _>::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<ValueSum, OverflowError>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue