Enum pact_models::bodies::OptionalBody
source · 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
impl OptionalBody
sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
If the body is present in the pact file and not empty or null.
sourcepub fn value_as_string(&self) -> Option<String>
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.
sourcepub 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
pub fn str_value(&self) -> &str
Returns the body if present as a UTF-8 string, otherwise returns the empty string.
sourcepub fn display_string(&self) -> String
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.
sourcepub fn has_content_type(&self) -> bool
pub fn has_content_type(&self) -> bool
If the body has a content type associated to it
sourcepub fn content_type(&self) -> Option<ContentType>
pub fn content_type(&self) -> Option<ContentType>
Parsed content type of the body
sourcepub fn with_content_type(&self, content_type: Option<ContentType>) -> Self
pub fn with_content_type(&self, content_type: Option<ContentType>) -> Self
Clones this body, setting the content type
sourcepub fn with_content_type_if_not_set(
&self,
content_type: Option<ContentType>
) -> Self
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
sourcepub fn to_v4_json(&self) -> Value
pub fn to_v4_json(&self) -> Value
Converts this body into a V4 Pact file JSON format
sourcepub fn set_content_type(&mut self, content_type: &ContentType)
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
impl Clone for OptionalBody
source§fn clone(&self) -> OptionalBody
fn clone(&self) -> OptionalBody
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for OptionalBody
impl Debug for OptionalBody
source§impl Default for OptionalBody
impl Default for OptionalBody
source§impl<'de> Deserialize<'de> for OptionalBody
impl<'de> Deserialize<'de> for OptionalBody
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for OptionalBody
impl Display for OptionalBody
source§impl From<&Value> for OptionalBody
impl From<&Value> for OptionalBody
source§impl<'a> From<&'a str> for OptionalBody
impl<'a> From<&'a str> for OptionalBody
source§impl From<String> for OptionalBody
impl From<String> for OptionalBody
source§impl From<Value> for OptionalBody
impl From<Value> for OptionalBody
source§impl Hash for OptionalBody
impl Hash for OptionalBody
source§impl PartialEq for OptionalBody
impl PartialEq for OptionalBody
source§impl Serialize for OptionalBody
impl Serialize for OptionalBody
impl Eq for OptionalBody
Auto Trait Implementations§
impl RefUnwindSafe for OptionalBody
impl Send for OptionalBody
impl Sync for OptionalBody
impl Unpin for OptionalBody
impl UnwindSafe for OptionalBody
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.