pub struct Response { /* private fields */ }
Expand description

HTTP response

Implementations§

source§

impl Response

source

pub fn new<S>(status: S) -> Self
where S: TryInto<StatusCode>, S::Error: Debug,

创建一个新的实例

source

pub fn builder<S>(status: S) -> ResponseBuilder
where S: TryInto<StatusCode>, S::Error: Debug,

source

pub fn status(&self) -> StatusCode

source

pub fn set_status<S>(&mut self, status: S)
where S: TryInto<StatusCode>, S::Error: Debug,

source

pub fn len(&self) -> Option<usize>

source

pub fn is_empty(&self) -> Option<bool>

source

pub fn header(&self, name: impl Into<HeaderName>) -> Option<&HeaderValues>

source

pub fn header_mut( &mut self, name: impl Into<HeaderName> ) -> Option<&mut HeaderValues>

source

pub fn remove_header( &mut self, name: impl Into<HeaderName> ) -> Option<HeaderValues>

source

pub fn insert_header( &mut self, key: impl Into<HeaderName>, value: impl ToHeaderValues )

source

pub fn append_header( &mut self, key: impl Into<HeaderName>, value: impl ToHeaderValues )

source

pub fn iter(&self) -> Iter<'_>

source

pub fn iter_mut(&mut self) -> IterMut<'_>

source

pub fn header_names(&self) -> Names<'_>

source

pub fn header_values(&self) -> Values<'_>

source

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

source

pub fn set_content_type(&mut self, mime: impl Into<Mime>)

source

pub fn set_body(&mut self, body: impl Into<Body>)

设置body读取.

source

pub fn take_body(&mut self) -> Body

source

pub fn swap_body(&mut self, body: &mut Body)

source

pub fn body_json(&mut self, json: &impl Serialize) -> Result<()>

source

pub fn body_string(&mut self, string: String)

source

pub fn body_bytes(&mut self, bytes: impl AsRef<[u8]>)

source

pub async fn body_file(&mut self, path: impl AsRef<Path>) -> Result<()>

source

pub fn error(&self) -> Option<&Error>

source

pub fn downcast_error<E>(&self) -> Option<&E>
where E: Display + Debug + Send + Sync + 'static,

source

pub fn take_error(&mut self) -> Option<Error>

source

pub fn set_error(&mut self, error: impl Into<Error>)

source

pub fn ext<T: Send + Sync + 'static>(&self) -> Option<&T>

source

pub fn insert_ext<T: Send + Sync + 'static>(&mut self, val: T)

source

pub fn from_res<T>(value: T) -> Self
where T: Into<Response>,

Trait Implementations§

source§

impl AsMut<Headers> for Response

source§

fn as_mut(&mut self) -> &mut Headers

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsMut<Response> for Response

source§

fn as_mut(&mut self) -> &mut Response

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Headers> for Response

source§

fn as_ref(&self) -> &Headers

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Response> for Response

source§

fn as_ref(&self) -> &Response

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for Response

source§

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

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

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

source§

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

Converts to this type from the input type.
source§

impl From<Body> for Response

source§

fn from(body: Body) -> Self

Converts to this type from the input type.
source§

impl From<Error> for Response

source§

fn from(err: Error) -> Self

Converts to this type from the input type.
source§

impl<State: Clone + Send + Sync + 'static> From<Request<State>> for Response

source§

fn from(request: Request<State>) -> Response

Converts to this type from the input type.
source§

impl From<Response> for Response

source§

fn from(response: Response) -> Response

Converts to this type from the input type.
source§

impl From<Response> for Response

source§

fn from(res: Response) -> Self

Converts to this type from the input type.
source§

impl From<ResponseBuilder> for Response

source§

fn from(response_builder: ResponseBuilder) -> Response

Converts to this type from the input type.
source§

impl From<StatusCode> for Response

source§

fn from(status: StatusCode) -> Self

Converts to this type from the input type.
source§

impl From<String> for Response

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<Value> for Response

source§

fn from(json_value: Value) -> Self

Converts to this type from the input type.
source§

impl Index<&str> for Response

§

type Output = HeaderValues

The returned type after indexing.
source§

fn index(&self, name: &str) -> &HeaderValues

Performs the indexing (container[index]) operation. Read more
source§

impl Index<HeaderName> for Response

§

type Output = HeaderValues

The returned type after indexing.
source§

fn index(&self, name: HeaderName) -> &HeaderValues

Performs the indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a Response

§

type Item = (&'a HeaderName, &'a HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Response

§

type Item = (&'a HeaderName, &'a mut HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Response

§

type Item = (HeaderName, HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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.

§

impl<T> Instrument for T

§

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

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

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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