Struct ExpectedStatusCodes

Source
pub struct ExpectedStatusCodes { /* private fields */ }
Expand description

Expected status codes for HTTP requests.

Supports multiple ranges and individual status codes for flexible validation.

Implementations§

Source§

impl ExpectedStatusCodes

Source

pub fn new() -> Self

Creates a new set of expected status codes with default range (200..500).

Source

pub fn add_single(self, status: u16) -> Self

Adds a single status code as valid.

Source

pub fn add_inclusive_range(self, range: RangeInclusive<u16>) -> Self

Adds an inclusive range of status codes.

Source

pub fn add_exclusive_range(self, range: Range<u16>) -> Self

Adds an exclusive range of status codes.

Source

pub fn from_inclusive_range(range: RangeInclusive<u16>) -> Self

Creates expected status codes from a single inclusive range.

§Panics

Panics if the range contains invalid HTTP status codes (outside 100-599).

Source

pub fn from_exclusive_range(range: Range<u16>) -> Self

Creates expected status codes from a single exclusive range.

§Panics

Panics if the range contains invalid HTTP status codes (outside 100-599).

Source

pub fn from_single(status: u16) -> Self

Creates expected status codes from a single status code.

§Panics

Panics if the status code is invalid (outside 100-599).

Source

pub fn from_status_code(status: StatusCode) -> Self

Creates expected status codes from a single http::StatusCode.

This method provides compile-time validation of status codes through the type system. Unlike the u16 variants, this method does not perform runtime validation since http::StatusCode guarantees valid HTTP status codes at compile time.

§Example
use clawspec_core::ExpectedStatusCodes;
use http::StatusCode;

let codes = ExpectedStatusCodes::from_status_code(StatusCode::OK);
assert!(codes.contains(200));
Source

pub fn from_status_code_range_inclusive( range: RangeInclusive<StatusCode>, ) -> Self

Creates expected status codes from an inclusive range of http::StatusCode.

This method provides compile-time validation of status codes through the type system. Unlike the u16 variants, this method does not perform runtime validation since http::StatusCode guarantees valid HTTP status codes at compile time.

§Example
use clawspec_core::ExpectedStatusCodes;
use http::StatusCode;

let codes = ExpectedStatusCodes::from_status_code_range_inclusive(
    StatusCode::OK..=StatusCode::NO_CONTENT
);
assert!(codes.contains(200));
assert!(codes.contains(204));
assert!(!codes.contains(205));
Source

pub fn from_status_code_range_exclusive(range: Range<StatusCode>) -> Self

Creates expected status codes from an exclusive range of http::StatusCode.

This method provides compile-time validation of status codes through the type system. Unlike the u16 variants, this method does not perform runtime validation since http::StatusCode guarantees valid HTTP status codes at compile time.

§Example
use clawspec_core::ExpectedStatusCodes;
use http::StatusCode;

let codes = ExpectedStatusCodes::from_status_code_range_exclusive(
    StatusCode::OK..StatusCode::PARTIAL_CONTENT
);
assert!(codes.contains(200));
assert!(codes.contains(204));
assert!(!codes.contains(206));
Source

pub fn contains(&self, status: u16) -> bool

Checks if a status code is expected/valid.

Source

pub fn contains_status_code(&self, status: StatusCode) -> bool

Checks if an http::StatusCode is expected/valid.

This is a convenience method that accepts http::StatusCode directly.

§Example
use clawspec_core::ExpectedStatusCodes;
use http::StatusCode;

let codes = ExpectedStatusCodes::from_status_code(StatusCode::OK);
assert!(codes.contains_status_code(StatusCode::OK));
assert!(!codes.contains_status_code(StatusCode::NOT_FOUND));
Source

pub fn add_expected_status(self, status: u16) -> Self

Adds a single expected status code (method used by ApiCall).

Source

pub fn add_expected_range(self, range: RangeInclusive<u16>) -> Self

Adds an expected inclusive range of status codes (method used by ApiCall).

Trait Implementations§

Source§

impl Clone for ExpectedStatusCodes

Source§

fn clone(&self) -> ExpectedStatusCodes

Returns a duplicate 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 ExpectedStatusCodes

Source§

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

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

impl Default for ExpectedStatusCodes

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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>,

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.
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> ErasedDestructor for T
where T: 'static,