pub struct Value { /* private fields */ }Expand description
A Simplicity value.
Implementations§
Source§impl Value
impl Value
Sourcepub fn shallow_clone(&self) -> Self
pub fn shallow_clone(&self) -> Self
Make a cheap copy of the value.
Sourcepub fn left(inner: Self, right: Arc<Final>) -> Self
pub fn left(inner: Self, right: Arc<Final>) -> Self
Create a left value that wraps the given inner value.
Sourcepub fn right(left: Arc<Final>, inner: Self) -> Self
pub fn right(left: Arc<Final>, inner: Self) -> Self
Create a right value that wraps the given inner value.
Sourcepub fn product(left: Self, right: Self) -> Self
pub fn product(left: Self, right: Self) -> Self
Create a product value that wraps the given left and right values.
Sourcepub fn buffer8_two_n_plus_one(
n: usize,
data: &[u8],
) -> Result<Self, Buffer8Error>
pub fn buffer8_two_n_plus_one( n: usize, data: &[u8], ) -> Result<Self, Buffer8Error>
Create a value of the type (TWO^8)^<2^(n+1) for the given n, populated
with the given slice’s data.
This type represents “a variable-length buffer of maximum length 2^(n+1) - 1”.
So for example, setting n = 5, the buffer can hold up to 63 bytes.
Sourcepub fn ctx8(
midstate: [u8; 32],
bytes_hashed: u64,
buffer: &[u8],
) -> Result<Self, Buffer8Error>
pub fn ctx8( midstate: [u8; 32], bytes_hashed: u64, buffer: &[u8], ) -> Result<Self, Buffer8Error>
Constructs a Ctx8 from raw parts.
Bear in mind that the count is a count of bytes, not a count of bits. For the
context to be valid (i.e. something that could be obtained by a sequence of hashing
operations), bytes_hashed % 64 must equal buffer.len().
You may want to obtain a hash engine and call Self::ctx8_from_hash_engine instead.
§Errors
Errors if the buffer exceeds the maximum length of a sha256 buffer (63 bytes).
Sourcepub fn ctx8_from_midstate(midstate: Midstate) -> Self
pub fn ctx8_from_midstate(midstate: Midstate) -> Self
Converts a SHA256 midstate into a Simplicity value.
Sourcepub fn ctx8_from_hash_engine(engine: &HashEngine) -> Self
pub fn ctx8_from_hash_engine(engine: &HashEngine) -> Self
Converts a SHA256 engine into a Simplicity value.
Sourcepub fn compact_len(&self) -> usize
pub fn compact_len(&self) -> usize
Return the bit length of the value in compact encoding.
Sourcepub fn padded_len(&self) -> usize
pub fn padded_len(&self) -> usize
Return the bit length of the value in padded encoding.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the value is a nested product of units. In this case, the value contains no information.
Sourcepub fn as_product(&self) -> Option<(ValueRef<'_>, ValueRef<'_>)>
pub fn as_product(&self) -> Option<(ValueRef<'_>, ValueRef<'_>)>
Access the inner values of a product value.
Sourcepub fn from_byte_array<const N: usize>(bytes: [u8; N]) -> Self
pub fn from_byte_array<const N: usize>(bytes: [u8; N]) -> Self
Sourcepub fn raw_byte_iter(&self) -> RawByteIter<'_>
pub fn raw_byte_iter(&self) -> RawByteIter<'_>
Yields an iterator over the “raw bytes” of the value.
The returned bytes match the padded bit-encoding of the value. You
may wish to call Self::iter_padded instead to obtain the bits,
but this method is more efficient in some contexts.
Sourcepub fn iter_compact(&self) -> CompactBitsIter<'_>
pub fn iter_compact(&self) -> CompactBitsIter<'_>
Return an iterator over the compact bit encoding of the value.
This encoding is used for writing witness data and for computing IHRs.
Sourcepub fn iter_padded(&self) -> PreOrderIter<'_>
pub fn iter_padded(&self) -> PreOrderIter<'_>
Return an iterator over the padded bit encoding of the value.
This encoding is used to represent the value in the Bit Machine.
Sourcepub fn is_of_type(&self, ty: &Final) -> bool
pub fn is_of_type(&self, ty: &Final) -> bool
Check if the value is of the given type.
Sourcepub fn zero(ty: &Final) -> Self
pub fn zero(ty: &Final) -> Self
Get the zero value for the given type.
The zero value serializes to a string of zeroes.
§Construction
zero( 1 )=()zero( A + B )=zero(A)zero( A × B )=zero(A) × zero(B)
Sourcepub fn to_word(&self) -> Option<Word>
pub fn to_word(&self) -> Option<Word>
Try to convert the value into a word.
The value is cheaply cloned.
Sourcepub fn prune(&self, pruned_ty: &Final) -> Option<Self>
pub fn prune(&self, pruned_ty: &Final) -> Option<Self>
Prune the value down to the given type.
The pruned type must be smaller than or equal to the current type of the value.
Otherwise, this method returns None.
§Smallness
T≤Tfor all typesT1≤Tfor all typesTA1 + B1≤A2 + B2ifA1≤A2andB1≤B2A1 × B1≤A2 × B2ifA1≤A2andB1≤B2
§Pruning
prune( v: T, 1 )=(): 1prune( L(l): A1 + B1, A2 + B2 )=prune(l: A1, A2) : A2 + B2prune( R(r): A1 + B1, A2 + B2 )=prune(r: B1, B2) : A2 + B2prune( (l, r): A1 × B1, A2 × B2 )=( prune(l: A1, A2), prune(r: B1, B2): A2 × B2
Source§impl Value
impl Value
Sourcepub fn from_compact_bits<I: Iterator<Item = u8>>(
bits: &mut BitIter<I>,
ty: &Final,
) -> Result<Self, EarlyEndOfStreamError>
pub fn from_compact_bits<I: Iterator<Item = u8>>( bits: &mut BitIter<I>, ty: &Final, ) -> Result<Self, EarlyEndOfStreamError>
Decode a value of the given type from its compact bit encoding.
Sourcepub fn from_padded_bits<I: Iterator<Item = u8>>(
bits: &mut BitIter<I>,
ty: &Final,
) -> Result<Self, EarlyEndOfStreamError>
pub fn from_padded_bits<I: Iterator<Item = u8>>( bits: &mut BitIter<I>, ty: &Final, ) -> Result<Self, EarlyEndOfStreamError>
Decode a value of the given type from its padded bit encoding.