Struct tsukuyomi::Input [−][src]
pub struct Input { /* fields omitted */ }
Contextual information used by processes during an incoming HTTP request.
Methods
impl Input
[src]
impl Input
pub fn with_current<R>(
f: impl FnOnce(&mut Self) -> R
) -> R
[src]
pub fn with_current<R>(
f: impl FnOnce(&mut Self) -> R
) -> R
Acquires a mutable borrow of Input
from the current task context and executes the provided
closure with its reference.
Panics
This function only work in the management of the framework and causes a panic
if any references to Input
is not set at the current task.
Do not use this function outside of futures returned by the handler functions.
Such situations often occurs by spawning tasks by the external Executor
(typically calling tokio::spawn()
).
In additional, this function forms a (dynamic) scope to prevent the references to Input
violate the borrowing rule in Rust.
Duplicate borrowings such as the following code are reported as a runtime error.
Input::with_current(|input| { some_process() }); fn some_process() { // Duplicate borrowing of `Input` occurs at this point. Input::with_current(|input| { ... }) }
pub fn is_set() -> bool
[src]
pub fn is_set() -> bool
Returns true
if the reference to Input
is set to the current task.
- Outside of
Future
managed by the framework. - A mutable borrow has already been acquired.
pub fn request(&self) -> &Request<RequestBody>
[src]
pub fn request(&self) -> &Request<RequestBody>
Returns a shared reference to the value of Request
contained in this context.
pub fn request_mut(&mut self) -> &mut Request<RequestBody>
[src]
pub fn request_mut(&mut self) -> &mut Request<RequestBody>
Returns a mutable reference to the value of Request
contained in this context.
pub fn header<H>(&self) -> Result<Option<H>, Error> where
H: Header,
[src]
pub fn header<H>(&self) -> Result<Option<H>, Error> where
H: Header,
Parses a header field in the request to a value of H
.
pub fn endpoint(&self) -> Option<&Endpoint>
[src]
pub fn endpoint(&self) -> Option<&Endpoint>
Returns the reference to a Endpoint
matched to the incoming request.
pub fn params(&self) -> Params
[src]
pub fn params(&self) -> Params
Returns a proxy object for accessing parameters extracted by the router.
ⓘImportant traits for &'a mut Rpub fn get<T>(&self) -> &T where
T: Send + Sync + 'static,
[src]
pub fn get<T>(&self) -> &T where
T: Send + Sync + 'static,
Returns the reference to a value of T
registered in the global storage.
Panics
This method will cause a panic if a value of T
is not registered in the global storage.
pub fn try_get<T>(&self) -> Option<&T> where
T: Send + Sync + 'static,
[src]
pub fn try_get<T>(&self) -> Option<&T> where
T: Send + Sync + 'static,
Returns the reference to a value of T
registered in the global storage, if possible.
This method will return a None
if a value of T
is not registered in the global storage.
Returns a proxy object for managing the value of Cookie entries.
This function will perform parsing when called at first, and returns an Err
if the value of header field is invalid.
Methods from Deref<Target = Request<RequestBody>>
pub fn method(&self) -> &Method
[src]
pub fn method(&self) -> &Method
Returns a reference to the associated HTTP method.
Examples
let request: Request<()> = Request::default(); assert_eq!(*request.method(), Method::GET);
pub fn method_mut(&mut self) -> &mut Method
[src]
pub fn method_mut(&mut self) -> &mut Method
Returns a mutable reference to the associated HTTP method.
Examples
let mut request: Request<()> = Request::default(); *request.method_mut() = Method::PUT; assert_eq!(*request.method(), Method::PUT);
pub fn uri(&self) -> &Uri
[src]
pub fn uri(&self) -> &Uri
Returns a reference to the associated URI.
Examples
let request: Request<()> = Request::default(); assert_eq!(*request.uri(), *"/");
pub fn uri_mut(&mut self) -> &mut Uri
[src]
pub fn uri_mut(&mut self) -> &mut Uri
Returns a mutable reference to the associated URI.
Examples
let mut request: Request<()> = Request::default(); *request.uri_mut() = "/hello".parse().unwrap(); assert_eq!(*request.uri(), *"/hello");
pub fn version(&self) -> Version
[src]
pub fn version(&self) -> Version
Returns the associated version.
Examples
let request: Request<()> = Request::default(); assert_eq!(request.version(), Version::HTTP_11);
pub fn version_mut(&mut self) -> &mut Version
[src]
pub fn version_mut(&mut self) -> &mut Version
Returns a mutable reference to the associated version.
Examples
let mut request: Request<()> = Request::default(); *request.version_mut() = Version::HTTP_2; assert_eq!(request.version(), Version::HTTP_2);
pub fn headers(&self) -> &HeaderMap<HeaderValue>
[src]
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Returns a reference to the associated header field map.
Examples
let request: Request<()> = Request::default(); assert!(request.headers().is_empty());
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
[src]
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
Returns a mutable reference to the associated header field map.
Examples
let mut request: Request<()> = Request::default(); request.headers_mut().insert(HOST, HeaderValue::from_static("world")); assert!(!request.headers().is_empty());
pub fn extensions(&self) -> &Extensions
[src]
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
Examples
let request: Request<()> = Request::default(); assert!(request.extensions().get::<i32>().is_none());
pub fn extensions_mut(&mut self) -> &mut Extensions
[src]
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns a mutable reference to the associated extensions.
Examples
let mut request: Request<()> = Request::default(); request.extensions_mut().insert("hello"); assert_eq!(request.extensions().get(), Some(&"hello"));
ⓘImportant traits for &'a mut Rpub fn body(&self) -> &T
[src]
pub fn body(&self) -> &T
Returns a reference to the associated HTTP body.
Examples
let request: Request<String> = Request::default(); assert!(request.body().is_empty());
ⓘImportant traits for &'a mut Rpub fn body_mut(&mut self) -> &mut T
[src]
pub fn body_mut(&mut self) -> &mut T
Returns a mutable reference to the associated HTTP body.
Examples
let mut request: Request<String> = Request::default(); request.body_mut().push_str("hello world"); assert!(!request.body().is_empty());
Trait Implementations
impl Debug for Input
[src]
impl Debug for Input
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Deref for Input
[src]
impl Deref for Input
type Target = Request<RequestBody>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl DerefMut for Input
[src]
impl DerefMut for Input