Trait arithmetic_typing::arith::Constraint

source ·
pub trait Constraint<Prim: PrimitiveType>: Display + Send + Sync + 'static {
    // Required methods
    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§

source

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

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.
source

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

Clones this constraint into a Box.

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

Trait Implementations§

source§

impl<Prim: PrimitiveType> Clone for Box<dyn Constraint<Prim>>

source§

fn clone(&self) -> Self

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<Prim: PrimitiveType> Debug for dyn Constraint<Prim>

source§

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

Formats the value using the given formatter. Read more

Implementors§

source§

impl<Prim: LinearType> Constraint<Prim> for Linearity

source§

impl<Prim: LinearType> Constraint<Prim> for Ops