Trait arithmetic_typing::arith::Constraint[][src]

pub trait Constraint<Prim: PrimitiveType>: Display + Send + Sync + 'static {
    fn visitor<'r>(
        &self,
        substitutions: &'r mut Substitutions<Prim>,
        errors: OpErrors<'r, Prim>
    ) -> Box<dyn Visit<Prim> + 'r>;
fn clone_boxed(&self) -> Box<dyn Constraint<Prim>>; }
Expand description

Constraint that can be placed on Types.

Constraints can be placed on Function type variables, and can be applied to types in TypeArithmetic impls. For example, NumArithmetic places the Linearity constraint on types involved in arithmetic ops.

The constraint mechanism is similar to trait constraints in Rust, but is much more limited:

  • Constraints cannot be parametric (cf. parameters in traits, such AsRef<_> or Iterator<Item = _>).
  • Constraints are applied to types in separation; it is impossible to create a constraint involving several type variables.
  • Constraints cannot contradict each other.

Implementation rules

  • Display must display constraint as an identifier (e.g., Lin). The string presentation of a constraint must be unique within a PrimitiveType; it is used to identify constraints in a ConstraintSet.

Required methods

fn visitor<'r>(
    &self,
    substitutions: &'r mut Substitutions<Prim>,
    errors: OpErrors<'r, Prim>
) -> Box<dyn Visit<Prim> + 'r>
[src]

Returns a Visitor that will be applied to constrained Types. The visitor may use substitutions to resolve types and errors to record constraint errors.

Tips

  • You can use StructConstraint for typical use cases, which involve recursively traversing ty.

fn clone_boxed(&self) -> Box<dyn Constraint<Prim>>[src]

Clones this constraint into a Box.

This method should be implemented by implementing Clone and boxing its output.

Trait Implementations

impl<Prim: PrimitiveType> Debug for dyn Constraint<Prim>[src]

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Implementors

impl<Prim: LinearType> Constraint<Prim> for Linearity[src]

fn visitor<'r>(
    &self,
    substitutions: &'r mut Substitutions<Prim>,
    errors: OpErrors<'r, Prim>
) -> Box<dyn Visit<Prim> + 'r>
[src]

fn clone_boxed(&self) -> Box<dyn Constraint<Prim>>[src]

impl<Prim: LinearType> Constraint<Prim> for Ops[src]

fn visitor<'r>(
    &self,
    substitutions: &'r mut Substitutions<Prim>,
    errors: OpErrors<'r, Prim>
) -> Box<dyn Visit<Prim> + 'r>
[src]

fn clone_boxed(&self) -> Box<dyn Constraint<Prim>>[src]