pub trait Pattern: Debug {
type Matches;
// Required methods
fn to_example(&self) -> Self::Matches;
fn to_example_bytes(&self) -> Vec<u8> ⓘ;
fn extract_matching_rules(
&self,
path: DocPath,
rules_out: &mut MatchingRuleCategory,
);
}Expand description
Abstract interface to types which can:
- Generate example data.
- 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§
Required Methods§
Sourcefn to_example(&self) -> Self::Matches
fn to_example(&self) -> Self::Matches
Convert this Matchable into an example data value, stripping out
any special match rules.
Sourcefn to_example_bytes(&self) -> Vec<u8> ⓘ
fn to_example_bytes(&self) -> Vec<u8> ⓘ
Convert this Matchable into an example data value as byte slice.
Sourcefn extract_matching_rules(
&self,
path: DocPath,
rules_out: &mut MatchingRuleCategory,
)
fn extract_matching_rules( &self, path: DocPath, rules_out: &mut MatchingRuleCategory, )
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.)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".