ProtoContext

Struct ProtoContext 

Source
pub struct ProtoContext<T> {
    pub body: Option<ProtoBody>,
    pub query_params: Option<HashMap<String, String>>,
    pub status: u16,
    pub hyper_request: Option<HyperRequest>,
    pub extra: T,
    /* private fields */
}

Fields§

§body: Option<ProtoBody>§query_params: Option<HashMap<String, String>>§status: u16§hyper_request: Option<HyperRequest>§extra: T

Implementations§

Source§

impl<T> ProtoContext<T>

Source

pub fn new(req: HyperRequest, extra: T) -> ProtoContext<T>

Source

pub fn status(&mut self, code: u32)

Set the response status code

Source

pub fn content_type(&mut self, c_type: &str)

Set the response Content-Type. A shortcode for

ctx.set("Content-Type", "some-val");
Source

pub fn redirect(&mut self, destination: &str)

Set up a redirect, will default to 302, but can be changed after the fact.

ctx.set("Location", "/some-path");
ctx.status(302);
Source

pub fn cookie(&mut self, name: &str, value: &str, options: &CookieOptions)

Sets a cookie on the response

Source

pub fn set_http2(&mut self)

Source

pub fn set_http11(&mut self)

Source

pub fn set_http10(&mut self)

Source

pub fn set_proto_status(&mut self, status: u16)

Trait Implementations§

Source§

impl<T> Clone for ProtoContext<T>

Source§

fn clone(&self) -> Self

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<T> Context for ProtoContext<T>

Source§

type Response = Response<ProtoBody>

Source§

fn get_response(self) -> Self::Response

get_response returns a fully created response object based on the contents of the Context. This means setting the body according to whatever has been stored via set_body and/or set_body_bytes, as well as adding the proper headers that have been added via the set method.
Source§

fn set_body(&mut self, body: Vec<u8>)

set_body is used to set the body using a vec of bytes on the context. The contents will be used later for generating the correct response.
Source§

fn set_body_bytes(&mut self, bytes: Bytes)

set_body_byte is used to set the body using a Bytes object on the context. The contents will be used later for generating the correct response.
Source§

fn route(&self) -> &str

route is used to return the route from the incoming request as a string.
Source§

fn set(&mut self, key: &str, value: &str)

set is used to set a header on the outgoing response.
Source§

fn remove(&mut self, key: &str)

remove is used to remove a header on the outgoing response.
Source§

fn status(&mut self, _status: u16)

sets the status on the response.
Source§

impl<T: Default> Default for ProtoContext<T>

Source§

fn default() -> ProtoContext<T>

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

impl<T> HasQueryParams for ProtoContext<T>

Source§

fn set_query_params(&mut self, query_params: HashMap<String, String>)

Source§

impl<T: Send> ProtoContextExt<T> for ProtoContext<T>

Source§

fn proto<'life0, 'async_trait, M>( &'life0 mut self, message: M, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where M: 'async_trait + Message + Default, Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_proto<'life0, 'async_trait, M>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<M, DecodeError>> + Send + 'async_trait>>
where M: 'async_trait + Message + Default, Self: 'async_trait, 'life0: 'async_trait,

Auto Trait Implementations§

§

impl<T> !Freeze for ProtoContext<T>

§

impl<T> !RefUnwindSafe for ProtoContext<T>

§

impl<T> Send for ProtoContext<T>
where T: Send,

§

impl<T> Sync for ProtoContext<T>
where T: Sync,

§

impl<T> Unpin for ProtoContext<T>
where T: Unpin,

§

impl<T> !UnwindSafe for ProtoContext<T>

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