pub trait Pattern: Debug {
    type Matches;

    fn to_example(&self) -> Self::Matches;
    fn extract_matching_rules(
        &self,
        path: DocPath,
        rules_out: &mut MatchingRuleCategory
    ); }
Expand description

Abstract interface to types which can:

  1. Generate example data.
  2. Match data returned by tests in various flexible ways, for example, accepting all strings which match a regular expression.

For an overview of how the matching rules work, and what kinds of special matching rules exist, see the pact_matching documentation.

The current version of this API will only work for JsonPattern and serde_json::Value. Extending this scheme to work for XML would require parameterizing the input and output types, and possibly other changes.

Required Associated Types

What type of data can this pattern be matched against? What kind of example data does it generate?

Required Methods

Convert this Matchable into an example data value, stripping out any special match rules.

Extract the matching rules from this Matchable, and insert them into rules_out, using path as the base path.

This API corresponds to the Extract code in Ruby.

(The path parameter is represented as a &str here, which forces each recursive call to allocate strings. We could optimize this by using a custom path representation which worked like a stack-based linked list stored in reverse order, but that would add significant complexity.)

Implementors