pub struct ParameterizedRoute { /* private fields */ }Expand description
Defines a route structure that can be used to define routes for a webserver.
Its templated sections can be easily populated to create a WebRoute
which can be used to make requests against the webserver routes that the
ParameterizedRoute was used to define.
Implementations§
Source§impl ParameterizedRoute
impl ParameterizedRoute
Sourcepub fn new<R: ToParameterizedSegments>(route: R) -> Self
pub fn new<R: ToParameterizedSegments>(route: R) -> Self
Creates a new ParameterizedRoute.
§Examples
use web_route::ParameterizedRoute;
let route = ParameterizedRoute::new("/some/route/{param}");Sourcepub fn join<R: ToParameterizedSegments>(&self, route: R) -> Self
pub fn join<R: ToParameterizedSegments>(&self, route: R) -> Self
Joins a route onto an existing ParameterizedRoute returning the
joined route.
§Examples
use web_route::ParameterizedRoute;
let route = ParameterizedRoute::new("/some/route/{param}");
let nested_route = ParameterizedRoute::new("/a/nested/route");
let joined_route = route.join(&nested_route);
assert_eq!(joined_route, route.join("/a/nested/route"))Sourcepub fn to_web_route<V: Serialize>(
&self,
values: &V,
) -> Result<WebRoute, WebRouteError>
pub fn to_web_route<V: Serialize>( &self, values: &V, ) -> Result<WebRoute, WebRouteError>
Attempts to populate the parameters of the route with their values and
returns a WebRoute.
values needs to implement serde::Serialize and be of an “Object”
style (with key-value pairs).
This would be used when making a request to an endpoint represented by the route.
§Errors
WebRouteError::UnpopulatedParamif no matching entry was found invaluesfor a particular parameter.WebRouteError::InvalidValueifvaluesdoes not contain key-value pairs.
§Examples
use web_route::ParameterizedRoute;
#[derive(serde::Serialize)]
struct RouteParams {
param: String,
}
let parameterized_route = ParameterizedRoute::new("/some/route/{param}");
let web_route = parameterized_route
.to_web_route(&RouteParams {
param: "value".to_owned(),
})
.unwrap();
assert_eq!(&web_route.to_string(), "/some/route/value")Trait Implementations§
Source§impl Clone for ParameterizedRoute
impl Clone for ParameterizedRoute
Source§fn clone(&self) -> ParameterizedRoute
fn clone(&self) -> ParameterizedRoute
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ParameterizedRoute
impl Debug for ParameterizedRoute
Source§impl Display for ParameterizedRoute
impl Display for ParameterizedRoute
Source§impl PartialEq for ParameterizedRoute
impl PartialEq for ParameterizedRoute
impl StructuralPartialEq for ParameterizedRoute
Auto Trait Implementations§
impl Freeze for ParameterizedRoute
impl RefUnwindSafe for ParameterizedRoute
impl Send for ParameterizedRoute
impl Sync for ParameterizedRoute
impl Unpin for ParameterizedRoute
impl UnwindSafe for ParameterizedRoute
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