Enum pact_consumer::patterns::JsonPattern
source · pub enum JsonPattern {
Json(Value),
Array(Vec<JsonPattern>),
Object(HashMap<String, JsonPattern>),
Pattern(Box<dyn Pattern<Matches = Value>>),
}
Expand description
A pattern which can be used to either:
- generate a sample JSON value using
to_json
, or - test whether a JSON value matches the pattern.
Many common Rust types may be converted into JSON patterns using into()
,
or the provided helper functions:
use pact_consumer::prelude::*;
let s: JsonPattern = "example".into();
let b: JsonPattern = true.into();
let v: JsonPattern = vec!["a", "b"].into();
let n = JsonPattern::null();
For more complicated values, see the json_pattern!
macro.
Variants§
Json(Value)
A regular JSON value, implemented by serde_json::Value
. Contains
no special matching rules.
Array(Vec<JsonPattern>)
An array of JSON patterns. May contain nested matching rules.
Object(HashMap<String, JsonPattern>)
An object containing JSON patterns. May contain nested matching rules.
Pattern(Box<dyn Pattern<Matches = Value>>)
A term which contains an arbitrary matchable. This is where rules like
Like
hook into our syntax.
Implementations§
source§impl JsonPattern
impl JsonPattern
sourcepub fn null() -> JsonPattern
pub fn null() -> JsonPattern
Construct a JSON null
value.
sourcepub fn pattern<P>(pattern: P) -> JsonPattern
pub fn pattern<P>(pattern: P) -> JsonPattern
Construct a JSON pattern from a type implementing Pattern
.
Trait Implementations§
source§impl Debug for JsonPattern
impl Debug for JsonPattern
source§impl<'a, T: Clone + Into<JsonPattern>> From<&'a [T]> for JsonPattern
impl<'a, T: Clone + Into<JsonPattern>> From<&'a [T]> for JsonPattern
source§impl<'a> From<&'a str> for JsonPattern
impl<'a> From<&'a str> for JsonPattern
source§impl From<DateTime<JsonPattern>> for JsonPattern
impl From<DateTime<JsonPattern>> for JsonPattern
source§fn from(pattern: DateTime<JsonPattern>) -> Self
fn from(pattern: DateTime<JsonPattern>) -> Self
Converts to this type from the input type.
source§impl From<EachLike> for JsonPattern
impl From<EachLike> for JsonPattern
source§impl From<HashMap<String, JsonPattern>> for JsonPattern
impl From<HashMap<String, JsonPattern>> for JsonPattern
source§impl From<Like<JsonPattern>> for JsonPattern
impl From<Like<JsonPattern>> for JsonPattern
source§fn from(pattern: Like<JsonPattern>) -> Self
fn from(pattern: Like<JsonPattern>) -> Self
Converts to this type from the input type.
source§impl From<ObjectMatching> for JsonPattern
impl From<ObjectMatching> for JsonPattern
source§fn from(pattern: ObjectMatching) -> Self
fn from(pattern: ObjectMatching) -> Self
Converts to this type from the input type.
source§impl From<String> for JsonPattern
impl From<String> for JsonPattern
source§impl From<Term<JsonPattern>> for JsonPattern
impl From<Term<JsonPattern>> for JsonPattern
source§fn from(pattern: Term<JsonPattern>) -> Self
fn from(pattern: Term<JsonPattern>) -> Self
Converts to this type from the input type.
source§impl From<Value> for JsonPattern
impl From<Value> for JsonPattern
source§impl<T: Into<JsonPattern>> From<Vec<T>> for JsonPattern
impl<T: Into<JsonPattern>> From<Vec<T>> for JsonPattern
source§impl From<bool> for JsonPattern
impl From<bool> for JsonPattern
source§impl From<f32> for JsonPattern
impl From<f32> for JsonPattern
source§impl From<f64> for JsonPattern
impl From<f64> for JsonPattern
source§impl From<i16> for JsonPattern
impl From<i16> for JsonPattern
source§impl From<i32> for JsonPattern
impl From<i32> for JsonPattern
source§impl From<i64> for JsonPattern
impl From<i64> for JsonPattern
source§impl From<i8> for JsonPattern
impl From<i8> for JsonPattern
source§impl From<isize> for JsonPattern
impl From<isize> for JsonPattern
source§impl From<u16> for JsonPattern
impl From<u16> for JsonPattern
source§impl From<u32> for JsonPattern
impl From<u32> for JsonPattern
source§impl From<u64> for JsonPattern
impl From<u64> for JsonPattern
source§impl From<u8> for JsonPattern
impl From<u8> for JsonPattern
source§impl From<usize> for JsonPattern
impl From<usize> for JsonPattern
source§impl<T: Into<JsonPattern>> FromIterator<T> for JsonPattern
impl<T: Into<JsonPattern>> FromIterator<T> for JsonPattern
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
source§impl Pattern for JsonPattern
impl Pattern for JsonPattern
§type Matches = Value
type Matches = Value
What type of data can this pattern be matched against? What kind of
example data does it generate?
source§fn to_example(&self) -> Value
fn to_example(&self) -> Value
Convert this
Matchable
into an example data value, stripping out
any special match rules.source§fn to_example_bytes(&self) -> Vec<u8> ⓘ
fn to_example_bytes(&self) -> Vec<u8> ⓘ
Convert this
Matchable
into an example data value as byte slice.source§fn 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. Read moreAuto Trait Implementations§
impl Freeze for JsonPattern
impl !RefUnwindSafe for JsonPattern
impl !Send for JsonPattern
impl !Sync for JsonPattern
impl Unpin for JsonPattern
impl !UnwindSafe for JsonPattern
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request