Struct nuclear::response::Response[][src]

pub struct Response { /* fields omitted */ }

Implementations

impl Response[src]

pub fn new(status: StatusCode, body: Body) -> Self[src]

pub fn new_ok(body: Body) -> Self[src]

pub fn text(s: impl Into<String>) -> Self[src]

pub fn json<T>(value: T) -> Result<Response, Error> where
    T: Serialize
[src]

pub fn with_status(self, status: StatusCode) -> Self[src]

Methods from Deref<Target = Response<Body>>

pub fn status(&self) -> StatusCode[src]

Returns the StatusCode.

Examples

let response: Response<()> = Response::default();
assert_eq!(response.status(), StatusCode::OK);

pub fn status_mut(&mut self) -> &mut StatusCode[src]

Returns a mutable reference to the associated StatusCode.

Examples

let mut response: Response<()> = Response::default();
*response.status_mut() = StatusCode::CREATED;
assert_eq!(response.status(), StatusCode::CREATED);

pub fn version(&self) -> Version[src]

Returns a reference to the associated version.

Examples

let response: Response<()> = Response::default();
assert_eq!(response.version(), Version::HTTP_11);

pub fn version_mut(&mut self) -> &mut Version[src]

Returns a mutable reference to the associated version.

Examples

let mut response: Response<()> = Response::default();
*response.version_mut() = Version::HTTP_2;
assert_eq!(response.version(), Version::HTTP_2);

pub fn headers(&self) -> &HeaderMap<HeaderValue>[src]

Returns a reference to the associated header field map.

Examples

let response: Response<()> = Response::default();
assert!(response.headers().is_empty());

pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>[src]

Returns a mutable reference to the associated header field map.

Examples

let mut response: Response<()> = Response::default();
response.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!response.headers().is_empty());

pub fn extensions(&self) -> &Extensions[src]

Returns a reference to the associated extensions.

Examples

let response: Response<()> = Response::default();
assert!(response.extensions().get::<i32>().is_none());

pub fn extensions_mut(&mut self) -> &mut Extensions[src]

Returns a mutable reference to the associated extensions.

Examples

let mut response: Response<()> = Response::default();
response.extensions_mut().insert("hello");
assert_eq!(response.extensions().get(), Some(&"hello"));

pub fn body(&self) -> &T[src]

Returns a reference to the associated HTTP body.

Examples

let response: Response<String> = Response::default();
assert!(response.body().is_empty());

pub fn body_mut(&mut self) -> &mut T[src]

Returns a mutable reference to the associated HTTP body.

Examples

let mut response: Response<String> = Response::default();
response.body_mut().push_str("hello world");
assert!(!response.body().is_empty());

Trait Implementations

impl Debug for Response[src]

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

Formats the value using the given formatter. Read more

impl Deref for Response[src]

type Target = Response<Body>

The resulting type after dereferencing.

fn deref(&self) -> &Self::Target[src]

Dereferences the value.

impl DerefMut for Response[src]

fn deref_mut(&mut self) -> &mut Self::Target[src]

Mutably dereferences the value.

impl From<&'_ str> for Response[src]

fn from(s: &str) -> Self[src]

Performs the conversion.

impl From<()> for Response[src]

fn from(_: ()) -> Self[src]

Performs the conversion.

impl From<StatusCode> for Response[src]

fn from(status: StatusCode) -> Self[src]

Performs the conversion.

impl From<StatusError> for Response[src]

fn from(e: StatusError) -> Self[src]

Performs the conversion.

impl From<String> for Response[src]

fn from(s: String) -> Self[src]

Performs the conversion.

impl<T> TryFrom<Json<T>> for Response where
    T: Serialize
[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(Json: Json<T>) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl TryFrom<Result<Response, Error>> for Response[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(ret: Result<Response>) -> Result<Self, Self::Error>[src]

Performs the conversion.

Auto Trait Implementations

impl !RefUnwindSafe for Response

impl Send for Response

impl Sync for Response

impl Unpin for Response

impl !UnwindSafe for Response

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

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

Notable traits for Instrumented<T>

impl<T> Future for Instrumented<T> where
    T: Future
type Output = <T as Future>::Output;
[src]

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

fn in_current_span(self) -> Instrumented<Self>

Notable traits for Instrumented<T>

impl<T> Future for Instrumented<T> where
    T: Future
type Output = <T as Future>::Output;
[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.