pub enum OptionalBody {
    Missing,
    Empty,
    Null,
    Present(Bytes, Option<ContentType>, Option<ContentTypeHint>),
}
Expand description

Enum that defines the four main states that a body of a request and response can be in a pact file.

Variants§

§

Missing

A body is missing if it is not present in the pact file

§

Empty

An empty body that is present in the pact file.

§

Null

A JSON body that is the null value. This state is to protect other language implementations from null values. It is treated as Empty.

§

Present(Bytes, Option<ContentType>, Option<ContentTypeHint>)

A non-empty body that is present in the pact file.

Implementations§

source§

impl OptionalBody

source

pub fn is_present(&self) -> bool

If the body is present in the pact file and not empty or null.

source

pub fn value(&self) -> Option<Bytes>

Returns the body if present, otherwise returns None.

source

pub fn value_as_string(&self) -> Option<String>

Returns the body as a UTF-8 string if present and is a textual form, otherwise returns None.

source

pub fn str_value(&self) -> &str

👎Deprecated since 0.4.2: This does not deal with binary bodies, use value_as_str or display_string instead

Returns the body if present as a UTF-8 string, otherwise returns the empty string.

source

pub fn display_string(&self) -> String

For text bodies (are present and have either a content type hint of TEXT or a content type that is a known textual form), returns the body as a UTF-8 string. Otherwise, if the body is present, will display the first 32 bytes in hexidecimal form. Otherwise returns the empty string.

source

pub fn has_content_type(&self) -> bool

If the body has a content type associated to it

source

pub fn content_type(&self) -> Option<ContentType>

Parsed content type of the body

source

pub fn with_content_type(&self, content_type: Option<ContentType>) -> Self

Clones this body, setting the content type

source

pub fn with_content_type_if_not_set( &self, content_type: Option<ContentType> ) -> Self

Clones this body, setting the content type if it is not set

source

pub fn to_v4_json(&self) -> Value

Converts this body into a V4 Pact file JSON format

source

pub fn set_content_type(&mut self, content_type: &ContentType)

Set the content type of the body. If the body is missing or empty, this is a no-op.

Trait Implementations§

source§

impl Clone for OptionalBody

source§

fn clone(&self) -> OptionalBody

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OptionalBody

source§

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

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

impl Default for OptionalBody

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for OptionalBody

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for OptionalBody

source§

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

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

impl From<&Value> for OptionalBody

source§

fn from(json: &Value) -> Self

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl From<String> for OptionalBody

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<Value> for OptionalBody

source§

fn from(json: Value) -> Self

Converts to this type from the input type.
source§

impl Hash for OptionalBody

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for OptionalBody

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for OptionalBody

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for OptionalBody

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> Fmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
§

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

§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,