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:

  1. generate a sample JSON value using to_json, or
  2. 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

source

pub fn null() -> JsonPattern

Construct a JSON null value.

source

pub fn pattern<P>(pattern: P) -> JsonPattern
where P: Pattern<Matches = Value> + 'static,

Construct a JSON pattern from a type implementing Pattern.

Trait Implementations§

source§

impl Debug for JsonPattern

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T: Clone + Into<JsonPattern>> From<&'a [T]> for JsonPattern

source§

fn from(arr: &'a [T]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for JsonPattern

source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for JsonPattern

source§

fn from(s: Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl From<DateTime<JsonPattern>> for JsonPattern

source§

fn from(pattern: DateTime<JsonPattern>) -> Self

Converts to this type from the input type.
source§

impl From<EachLike> for JsonPattern

source§

fn from(pattern: EachLike) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<String, JsonPattern>> for JsonPattern

source§

fn from(m: Map<String, JsonPattern>) -> Self

Converts to this type from the input type.
source§

impl From<Like<JsonPattern>> for JsonPattern

source§

fn from(pattern: Like<JsonPattern>) -> Self

Converts to this type from the input type.
source§

impl From<Map<String, Value>> for JsonPattern

source§

fn from(n: Map<String, Value>) -> Self

Converts to this type from the input type.
source§

impl From<ObjectMatching> for JsonPattern

source§

fn from(pattern: ObjectMatching) -> Self

Converts to this type from the input type.
source§

impl From<String> for JsonPattern

source§

fn from(n: String) -> Self

Converts to this type from the input type.
source§

impl From<Term<JsonPattern>> for JsonPattern

source§

fn from(pattern: Term<JsonPattern>) -> Self

Converts to this type from the input type.
source§

impl From<Value> for JsonPattern

source§

fn from(j: Value) -> Self

Converts to this type from the input type.
source§

impl<T: Into<JsonPattern>> From<Vec<T>> for JsonPattern

source§

fn from(arr: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for JsonPattern

source§

fn from(n: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for JsonPattern

source§

fn from(n: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for JsonPattern

source§

fn from(n: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for JsonPattern

source§

fn from(n: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for JsonPattern

source§

fn from(n: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for JsonPattern

source§

fn from(n: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for JsonPattern

source§

fn from(n: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for JsonPattern

source§

fn from(n: isize) -> Self

Converts to this type from the input type.
source§

impl From<u16> for JsonPattern

source§

fn from(n: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for JsonPattern

source§

fn from(n: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for JsonPattern

source§

fn from(n: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for JsonPattern

source§

fn from(n: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for JsonPattern

source§

fn from(n: usize) -> Self

Converts to this type from the input type.
source§

impl<T: Into<JsonPattern>> FromIterator<T> for JsonPattern

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl Pattern for JsonPattern

§

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

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

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 )

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more