[][src]Trait dqcsim::common::converter::Converter

pub trait Converter {
    type Input;
    type Output;
    fn detect(&self, input: &Self::Input) -> Result<Option<Self::Output>>;
fn construct(&self, input: &Self::Output) -> Result<Self::Input>; }

A type that can be used as a Converter.

Types implementing Converter can be used to detect inputs and link them to their outputs, and vice versa. The output is always a specific case of the input, so detection can fail in the sense that a given input is not an instance of the output type, while the opposite cannot fail this way.

A collection of types implementing Converter can be used in a ConverterMap to convert common types to plugin-specific types and back. This is primarily used for the C API, where the user cannot define their own converter traits to do the equivalent more ergonomically.

Associated Types

type Input

The more generic detector input type = constructor output type.

type Output

The more specific detector output type = constructor input type.

Loading content...

Required methods

fn detect(&self, input: &Self::Input) -> Result<Option<Self::Output>>

The detect function implements the detector function. The return values are as follows:

  • Ok(Some(O)): successful match
  • Ok(None): the input is not an instance of the output type
  • Err(_): something went wrong during detection

fn construct(&self, input: &Self::Output) -> Result<Self::Input>

The construct function implements the opposite of the detector function, converting the plugin-specific type to the more generic type.

  • Ok(O): successful construction
  • Err(_): something went wrong during construction
Loading content...

Implementors

impl Converter for MeasurementGateConverter[src]

type Input = Gate

type Output = (Vec<QubitRef>, ArbData)

impl Converter for PrepGateConverter[src]

type Input = Gate

type Output = (Vec<QubitRef>, ArbData)

impl<'c, I, K, O> Converter for ConverterMap<'c, K, I, O> where
    K: Eq + Hash + Clone,
    I: Eq + Hash + Clone,
    O: Clone
[src]

type Input = I

type Output = (K, O)

impl<'f> Converter for CustomGateConverter<'f>[src]

type Input = Gate

type Output = (Vec<QubitRef>, ArbData)

impl<M> Converter for UnitaryGateConverter<M> where
    M: Converter<Input = (Matrix, Option<usize>)>,
    M::Output: FromArb + ToArb
[src]

type Input = Gate

type Output = (Vec<QubitRef>, ArbData)

impl<T> Converter for UnitaryConverter<T> where
    T: MatrixConverter
[src]

type Input = (Matrix, Option<usize>)

type Output = T::Parameters

impl<T> Converter for T where
    T: MatrixConverter
[src]

type Input = (Matrix, f64, bool)

type Output = T::Parameters

Loading content...