Struct simplicity::types::Type

source ·
pub struct Type { /* private fields */ }
Expand description

Source or target type of a Simplicity expression.

Internally this type is essentially just a refcounted pointer; it is therefore quite cheap to clone, but be aware that cloning will not actually create a new independent type, just a second pointer to the first one.

Implementations§

source§

impl Type

source

pub fn free(name: String) -> Self

Return an unbound type with the given name

source

pub fn unit() -> Self

Return a unit type.

source

pub fn two_two_n(n: usize) -> Self

Return a precomputed copy of 2^(2^n), for given n.

source

pub fn sum(a: Self, b: Self) -> Self

Return the sum of the given two types.

source

pub fn product(a: Self, b: Self) -> Self

Return the product of the given two types.

source

pub fn shallow_clone(&self) -> Type

Clones the Type.

This is the same as just calling .clone() but has a different name to emphasize that what’s being cloned is merely a ref-counted pointer.

source

pub fn bind(&self, bound: Arc<Bound>, hint: &'static str) -> Result<(), Error>

Binds the type to a given bound. If this fails, attach the provided hint to the error.

Fails if the type has an existing incompatible bound.

source

pub fn unify(&self, other: &Self, hint: &'static str) -> Result<(), Error>

Unify the type with another one.

Fails if the bounds on the two types are incompatible

source

pub fn bound(&self) -> Arc<Bound>

Accessor for this type’s bound

source

pub fn tmr(&self) -> Option<Tmr>

Accessor for the TMR of this type, if it is final

source

pub fn final_data(&self) -> Option<Arc<Final>>

Accessor for the data of this type, if it is complete

source

pub fn is_final(&self) -> bool

Whether this type is known to be final

During type inference this may be false even though the type is, in fact, complete, since its children may have been unified to a complete type. To ensure a type is complete, call Type::finalize.

source

pub fn finalize(&self) -> Result<Arc<Final>, Error>

Attempts to finalize the type. Returns its TMR on success.

source

pub fn powers_of_two(n: usize) -> Vec<Self>

Return a vector containing the types 2^(2^i) for i from 0 to n-1.

Trait Implementations§

source§

impl Clone for Type

source§

fn clone(&self) -> Type

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl DagLike for Type

§

type Node = Type

The type of the DAG node, with no references or wrappers
source§

fn data(&self) -> &Type

A pointer to the underlying data
source§

fn as_dag_node(&self) -> Dag<Self>

Interpret the node as a DAG node
source§

fn left_child(&self) -> Option<Self>

Accessor for the left child of the node, if one exists
source§

fn right_child(&self) -> Option<Self>

Accessor for the right child of the node, if one exists
source§

fn n_children(&self) -> usize

Number of children that the node has. Read more
source§

fn rtl_post_order_iter<S: SharingTracker<SwapChildren<Self>> + Default>( self ) -> RtlPostOrderIter<Self, S>

Obtains an iterator of all the nodes rooted at the DAG, in right-to-left post order. Read more
source§

fn pre_order_iter<S: SharingTracker<Self> + Default>( self ) -> PreOrderIter<Self, S>

Obtains an iterator of all the nodes rooted at the DAG, in pre-order.
source§

fn verbose_pre_order_iter<S: SharingTracker<Self> + Default>( self ) -> VerbosePreOrderIter<Self, S>
where Self: Clone,

Obtains a verbose iterator of all the nodes rooted at the DAG, in pre-order. Read more
source§

fn post_order_iter<S: SharingTracker<Self> + Default>( self ) -> PostOrderIter<Self, S>

Obtains an iterator of all the nodes rooted at the DAG, in post order. Read more
source§

fn is_shared_as<S: SharingTracker<Self> + Default>(self) -> bool
where Self: Clone,

Checks whether a DAG’s internal sharing (as expressed by shared pointers) matches the given target sharing.
source§

fn post_order_iter_with_tracker<S: SharingTracker<Self>>( self, tracker: S ) -> PostOrderIter<Self, S>

Obtains an post-order iterator of all the nodes rooted at DAG, using the given tracker. Read more
source§

impl Debug for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Bound> for Type

source§

fn from(bound: Bound) -> Type

Promotes a Bound to a type defined by that constraint

Auto Trait Implementations§

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V