Trait TypeMapping

Source
pub trait TypeMapping {
    type InV<'c>: Clone;
    type OutV<'c>;
    type SumOutV<'c>;
    type FuncOutV<'c>;

    // Required methods
    fn map_sum_type<'c>(
        &self,
        sum_type: &HugrSumType,
        inv: Self::InV<'c>,
        variants: impl IntoIterator<Item = Vec<Self::OutV<'c>>>,
    ) -> Result<Self::SumOutV<'c>>;
    fn map_function_type<'c>(
        &self,
        function_type: &HugrFuncType,
        inv: Self::InV<'c>,
        inputs: impl IntoIterator<Item = Self::OutV<'c>>,
        outputs: impl IntoIterator<Item = Self::OutV<'c>>,
    ) -> Result<Self::FuncOutV<'c>>;
    fn sum_into_out<'c>(&self, sum: Self::SumOutV<'c>) -> Self::OutV<'c>;
    fn func_into_out<'c>(&self, sum: Self::FuncOutV<'c>) -> Self::OutV<'c>;

    // Provided method
    fn default_out<'c>(
        &self,
        inv: Self::InV<'c>,
        hugr_type: &HugrType,
    ) -> Result<Self::OutV<'c>> { ... }
}
Expand description

Defines a mapping from HugrType to OutV;

Required Associated Types§

Source

type InV<'c>: Clone

Auxiliary data provided when mapping from a HugrType.

Source

type OutV<'c>

The target type of the mapping.

Source

type SumOutV<'c>

The target type when mapping from HugrSumTypes. This type must be convertible to OutV via sum_into_out.

Source

type FuncOutV<'c>

The target type when mapping from HugrFuncTypes. This type must be convertible to OutV via func_into_out.

Required Methods§

Source

fn map_sum_type<'c>( &self, sum_type: &HugrSumType, inv: Self::InV<'c>, variants: impl IntoIterator<Item = Vec<Self::OutV<'c>>>, ) -> Result<Self::SumOutV<'c>>

Returns the result of the mapping on sum_type, with auxiliary data inv, and when the result of mapping all fields of all variants is given by variants.

Source

fn map_function_type<'c>( &self, function_type: &HugrFuncType, inv: Self::InV<'c>, inputs: impl IntoIterator<Item = Self::OutV<'c>>, outputs: impl IntoIterator<Item = Self::OutV<'c>>, ) -> Result<Self::FuncOutV<'c>>

Returns the result of the mapping on function_type, with auxiliary data inv, and when the result of mapping all inputs is given by inputs and the result of mapping all outputs is given by outputs.

Source

fn sum_into_out<'c>(&self, sum: Self::SumOutV<'c>) -> Self::OutV<'c>

Infallibly convert from the result of map_sum_type to the result of the mapping.

Source

fn func_into_out<'c>(&self, sum: Self::FuncOutV<'c>) -> Self::OutV<'c>

Infallibly convert from the result of map_functype to the result of the mapping.

Provided Methods§

Source

fn default_out<'c>( &self, inv: Self::InV<'c>, hugr_type: &HugrType, ) -> Result<Self::OutV<'c>>

Construct an appropriate result of the mapping when hugr_type is not a function, sum, registered custom type, or composition of same.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§