Enum pact_consumer::prelude::JsonPattern
source · [−]pub enum JsonPattern {
Json(Value),
Array(Vec<JsonPattern>),
Object(Map<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(Map<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
sourceimpl JsonPattern
impl JsonPattern
sourcepub fn null() -> JsonPattern
pub fn null() -> JsonPattern
Construct a JSON null
value.
sourcepub fn pattern<P>(pattern: P) -> JsonPattern where
P: Pattern<Matches = Value> + 'static,
pub fn pattern<P>(pattern: P) -> JsonPattern where
P: Pattern<Matches = Value> + 'static,
Construct a JSON pattern from a type implementing Pattern
.
Trait Implementations
sourceimpl Debug for JsonPattern
impl Debug for JsonPattern
sourceimpl<'a, T: Clone + Into<JsonPattern>> From<&'a [T]> for JsonPattern
impl<'a, T: Clone + Into<JsonPattern>> From<&'a [T]> for JsonPattern
sourceimpl<'a> From<&'a str> for JsonPattern
impl<'a> From<&'a str> for JsonPattern
sourceimpl<'a> From<Cow<'a, str>> for JsonPattern
impl<'a> From<Cow<'a, str>> for JsonPattern
sourceimpl From<DateTime<JsonPattern>> for JsonPattern
impl From<DateTime<JsonPattern>> for JsonPattern
sourcefn from(pattern: DateTime<JsonPattern>) -> Self
fn from(pattern: DateTime<JsonPattern>) -> Self
Converts to this type from the input type.
sourceimpl From<EachLike> for JsonPattern
impl From<EachLike> for JsonPattern
sourceimpl From<HashMap<String, JsonPattern, RandomState>> for JsonPattern
impl From<HashMap<String, JsonPattern, RandomState>> for JsonPattern
sourcefn from(m: Map<String, JsonPattern>) -> Self
fn from(m: Map<String, JsonPattern>) -> Self
Converts to this type from the input type.
sourceimpl From<Like<JsonPattern>> for JsonPattern
impl From<Like<JsonPattern>> for JsonPattern
sourcefn from(pattern: Like<JsonPattern>) -> Self
fn from(pattern: Like<JsonPattern>) -> Self
Converts to this type from the input type.
sourceimpl From<String> for JsonPattern
impl From<String> for JsonPattern
sourceimpl From<Term<JsonPattern>> for JsonPattern
impl From<Term<JsonPattern>> for JsonPattern
sourcefn from(pattern: Term<JsonPattern>) -> Self
fn from(pattern: Term<JsonPattern>) -> Self
Converts to this type from the input type.
sourceimpl From<Value> for JsonPattern
impl From<Value> for JsonPattern
sourceimpl<T: Into<JsonPattern>> From<Vec<T, Global>> for JsonPattern
impl<T: Into<JsonPattern>> From<Vec<T, Global>> for JsonPattern
sourceimpl From<bool> for JsonPattern
impl From<bool> for JsonPattern
sourceimpl From<f32> for JsonPattern
impl From<f32> for JsonPattern
sourceimpl From<f64> for JsonPattern
impl From<f64> for JsonPattern
sourceimpl From<i16> for JsonPattern
impl From<i16> for JsonPattern
sourceimpl From<i32> for JsonPattern
impl From<i32> for JsonPattern
sourceimpl From<i64> for JsonPattern
impl From<i64> for JsonPattern
sourceimpl From<i8> for JsonPattern
impl From<i8> for JsonPattern
sourceimpl From<isize> for JsonPattern
impl From<isize> for JsonPattern
sourceimpl From<u16> for JsonPattern
impl From<u16> for JsonPattern
sourceimpl From<u32> for JsonPattern
impl From<u32> for JsonPattern
sourceimpl From<u64> for JsonPattern
impl From<u64> for JsonPattern
sourceimpl From<u8> for JsonPattern
impl From<u8> for JsonPattern
sourceimpl From<usize> for JsonPattern
impl From<usize> for JsonPattern
sourceimpl<T: Into<JsonPattern>> FromIterator<T> for JsonPattern
impl<T: Into<JsonPattern>> FromIterator<T> for JsonPattern
sourcefn 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
sourceimpl 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? Read more
sourcefn to_example(&self) -> Value
fn to_example(&self) -> Value
Convert this Matchable
into an example data value, stripping out
any special match rules. Read more
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. Read more
Auto Trait Implementations
impl !RefUnwindSafe for JsonPattern
impl !Send for JsonPattern
impl !Sync for JsonPattern
impl Unpin for JsonPattern
impl !UnwindSafe for JsonPattern
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
impl<T> Pointable for T
impl<T> Pointable for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more