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<_>orIterator<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
Displaymust display constraint as an identifier (e.g.,Lin). The string presentation of a constraint must be unique within aPrimitiveType; it is used to identify constraints in aConstraintSet.
Required Methods§
Sourcefn visitor<'r>(
&self,
substitutions: &'r mut Substitutions<Prim>,
errors: OpErrors<'r, Prim>,
) -> Box<dyn Visit<Prim> + 'r>
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
StructConstraintfor typical use cases, which involve recursively traversingty.
Sourcefn clone_boxed(&self) -> Box<dyn Constraint<Prim>>
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.