Skip to main content

Responses

Struct Responses 

Source
pub struct Responses {
    pub default_response: Option<RefOr<Response>>,
    pub responses: Map<RefOr<Response>>,
    pub extensions: Extensions,
}
Expand description

The responses an operation may return.

Serializes with default_response under the default key, each entry of responses under its status pattern, and extensions alongside them.

Fields§

§default_response: Option<RefOr<Response>>

The response used for status codes not otherwise covered.

§responses: Map<RefOr<Response>>

Responses keyed by status code or wildcard.

§extensions: Extensions

Specification extensions.

Implementations§

Source§

impl Responses

Source

pub fn new() -> Self

Creates an empty set of responses.

A description must not keep it empty: the specification requires at least one response, and crate::validate reports the omission.

Source

pub fn with(self, status: u16, response: Response) -> Self

Declares a response for an exact status code.

Source

pub fn with_pattern( self, pattern: StatusPattern, response: RefOr<Response>, ) -> Self

Declares a response for a status pattern.

Source

pub fn with_default(self, response: Response) -> Self

Sets the fallback response.

Source

pub fn is_empty(&self) -> bool

Returns true when nothing at all is declared.

Extensions count. Operation.responses is skipped when this is true, so ignoring them would silently drop a Responses that carries only x- fields — which is exactly the drop a round trip must not make.

This is therefore not the question the specification’s “MUST contain at least one response code” asks. declares_a_response is.

Source

pub fn declares_a_response(&self) -> bool

Returns true when a status code or default is declared.

The distinction from is_empty is the whole point: an extension is not a response, so a Responses Object carrying only x- fields is not empty and still declares nothing.

Source

pub fn get(&self, status: u16) -> Option<&RefOr<Response>>

Looks up the response declared for an exact status code.

Only exact keys are considered; wildcard resolution is a consumer concern and depends on precedence rules this method does not apply.

Source

pub fn merge_from(&mut self, other: &Self)

Merges another set into this one, keeping existing entries on conflict.

This is how an interceptor’s declared responses join an operation’s own.

Trait Implementations§

Source§

impl Clone for Responses

Source§

fn clone(&self) -> Responses

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Responses

Source§

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

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

impl Default for Responses

Source§

fn default() -> Responses

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

impl<'de> Deserialize<'de> for Responses

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl PartialEq for Responses

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Responses

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

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

impl StructuralPartialEq for Responses

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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>,

Source§

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.