Enum simplicity::Value
source · pub enum Value {
Unit,
SumL(Arc<Value>),
SumR(Arc<Value>),
Prod(Arc<Value>, Arc<Value>),
}Expand description
Value of some type.
The unit value is the only value of the unit type. This is the basis for everything we are doing. Because there is only a single unit value, there is no information contained in it. Instead, we wrap unit values in sum and product values to encode information.
A sum value wraps another value.
The left sum value L(a) wraps a value a from the left type A.
The right sum value R(b) wraps a value b from the right type B.
The type of the sum value is the sum type A + B of the left type and the right type.
We represent the false bit as a left value that wraps a unit value. The true bit is represented as a right value that wraps a unit value.
A product value (a, b) wraps two values:
a value a from the left type A and a value b from the right type B.
The type of the product value is the product type A × B of the left type and the right type.
We represent bit strings (tuples of bits) as trees of nested product values that have bit values (sum values wrapping the unit value) at their leaves.
Variants§
Unit
Unit value
SumL(Arc<Value>)
Sum value that wraps a left value
SumR(Arc<Value>)
Sum value that wraps a right value
Prod(Arc<Value>, Arc<Value>)
Product value that wraps a left and a right value
Implementations§
source§impl Value
impl Value
sourcepub fn prod(left: Arc<Self>, right: Arc<Self>) -> Arc<Self>
pub fn prod(left: Arc<Self>, right: Arc<Self>) -> Arc<Self>
Create a product value that wraps a left and a right value.
sourcepub fn u1(n: u8) -> Arc<Self>
pub fn u1(n: u8) -> Arc<Self>
Encode a single bit as a value. Will panic if the input is out of range
sourcepub fn u2(n: u8) -> Arc<Self>
pub fn u2(n: u8) -> Arc<Self>
Encode a two-bit number as a value. Will panic if the input is out of range
sourcepub fn u4(n: u8) -> Arc<Self>
pub fn u4(n: u8) -> Arc<Self>
Encode a four-bit number as a value. Will panic if the input is out of range
sourcepub fn u256_from_slice(v: &[u8]) -> Arc<Self>
pub fn u256_from_slice(v: &[u8]) -> Arc<Self>
Encode a 32-byte number as a value
Useful for encoding public keys and hashes
sourcepub fn u512_from_slice(v: &[u8]) -> Arc<Self>
pub fn u512_from_slice(v: &[u8]) -> Arc<Self>
Encode a 64-byte number as a value
Useful for encoding signatures
sourcepub fn power_of_two(v: &[u8]) -> Arc<Self>
pub fn power_of_two(v: &[u8]) -> Arc<Self>
Encode a byte slice as a value.
The length of the slice must be a power of two.
sourcepub fn do_each_bit<F>(&self, f: F)
pub fn do_each_bit<F>(&self, f: F)
Execute function f on each bit of the encoding of the value.
sourcepub fn try_to_bytes(&self) -> Result<Vec<u8>, &str>
pub fn try_to_bytes(&self) -> Result<Vec<u8>, &str>
Encode value as big-endian byte string. Fails if underlying bit string has length not divisible by 8
sourcepub fn to_bytes_len(&self) -> (Vec<u8>, usize)
pub fn to_bytes_len(&self) -> (Vec<u8>, usize)
Encode value as big-endian byte string. Trailing zeroes are added as padding if underlying bit string has length not divisible by 8. The length of said bit string is returned as second argument
Trait Implementations§
source§impl<'a> DagLike for &'a Value
impl<'a> DagLike for &'a Value
source§fn as_dag_node(&self) -> Dag<Self>
fn as_dag_node(&self) -> Dag<Self>
source§fn left_child(&self) -> Option<Self>
fn left_child(&self) -> Option<Self>
source§fn right_child(&self) -> Option<Self>
fn right_child(&self) -> Option<Self>
source§fn n_children(&self) -> usize
fn n_children(&self) -> usize
source§fn rtl_post_order_iter<S: SharingTracker<SwapChildren<Self>> + Default>(
self
) -> RtlPostOrderIter<Self, S>
fn rtl_post_order_iter<S: SharingTracker<SwapChildren<Self>> + Default>( self ) -> RtlPostOrderIter<Self, S>
source§fn pre_order_iter<S: SharingTracker<Self> + Default>(
self
) -> PreOrderIter<Self, S> ⓘ
fn pre_order_iter<S: SharingTracker<Self> + Default>( self ) -> PreOrderIter<Self, S> ⓘ
source§fn verbose_pre_order_iter<S: SharingTracker<Self> + Default>(
self
) -> VerbosePreOrderIter<Self, S> ⓘwhere
Self: Clone,
fn verbose_pre_order_iter<S: SharingTracker<Self> + Default>(
self
) -> VerbosePreOrderIter<Self, S> ⓘwhere
Self: Clone,
source§fn post_order_iter<S: SharingTracker<Self> + Default>(
self
) -> PostOrderIter<Self, S> ⓘ
fn post_order_iter<S: SharingTracker<Self> + Default>( self ) -> PostOrderIter<Self, S> ⓘ
source§fn post_order_iter_with_tracker<S: SharingTracker<Self>>(
self,
tracker: S
) -> PostOrderIter<Self, S> ⓘ
fn post_order_iter_with_tracker<S: SharingTracker<Self>>( self, tracker: S ) -> PostOrderIter<Self, S> ⓘ
source§impl Ord for Value
impl Ord for Value
source§impl PartialEq for Value
impl PartialEq for Value
source§impl PartialOrd for Value
impl PartialOrd for Value
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more