pub struct Params<'k, 'v> { /* private fields */ }Expand description
Matcher parameters.
This is a thin wrapper around the Params data type of the matchit
crate to shield against unforeseen changes in the crate’s implementation.
Note that Params should be used without lifetime parameters, as it’s
designed to be used in a context where lifetimes are irrelevant, i.e., in
the signature of an Action, ensuring that third-party integrations
don’t break when the implementation changes, albeit unlikely.
Implementations§
Source§impl<'k, 'v> Params<'k, 'v>
impl<'k, 'v> Params<'k, 'v>
Sourcepub fn get<K>(&self, key: K) -> Option<&'v str>
pub fn get<K>(&self, key: K) -> Option<&'v str>
Returns the value for the given key.
§Examples
use zapient::http::{Request, Response, Status};
use zapient::router::{Router, Params};
// Create router and add route
let router = Router::default()
.get("/coffee/{kind}", |req: Request, params: Params| {
if let Some(kind) = params.get("kind") {
Response::default() // Handle request
} else {
Response::new().status(Status::BadRequest)
}
});Sourcepub fn contains<K>(&self, key: K) -> bool
pub fn contains<K>(&self, key: K) -> bool
Returns whether the parameter is contained.
§Examples
use zapient::http::{Request, Response, Status};
use zapient::router::{Router, Params};
// Create router and add route
let router = Router::default()
.get("/coffee/{kind}", |req: Request, params: Params| {
if params.contains("kind") {
Response::default() // Handle request
} else {
Response::new().status(Status::BadRequest)
}
});Sourcepub fn iter(&self) -> ParamsIter<'_, 'k, 'v>
pub fn iter(&self) -> ParamsIter<'_, 'k, 'v>
Returns an iterator over all parameters.
§Examples
use zapient::http::{Request, Response};
use zapient::router::{Router, Params};
// Create router and add route
let router = Router::default()
.get("/coffee/{kind}", |req: Request, params: Params| {
for (key, value) in params.iter() {
println!("{key}: {value}");
}
Response::default() // Handle request
});Trait Implementations§
Source§impl<'a, 'k, 'v> IntoIterator for &'a Params<'k, 'v>
impl<'a, 'k, 'v> IntoIterator for &'a Params<'k, 'v>
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates an iterator over all parameters.
§Examples
use zapient::http::{Request, Response};
use zapient::router::{Router, Params};
// Create router and add route
let router = Router::default()
.get("/coffee/{kind}", |req: Request, params: Params| {
for (key, value) in ¶ms {
println!("{key}: {value}");
}
Response::default() // Handle request
});Source§type IntoIter = ParamsIter<'a, 'k, 'v>
type IntoIter = ParamsIter<'a, 'k, 'v>
Which kind of iterator are we turning this into?
Auto Trait Implementations§
impl<'k, 'v> Freeze for Params<'k, 'v>
impl<'k, 'v> RefUnwindSafe for Params<'k, 'v>
impl<'k, 'v> Send for Params<'k, 'v>
impl<'k, 'v> Sync for Params<'k, 'v>
impl<'k, 'v> Unpin for Params<'k, 'v>
impl<'k, 'v> UnsafeUnpin for Params<'k, 'v>
impl<'k, 'v> UnwindSafe for Params<'k, 'v>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more