pub struct WebRoute { /* private fields */ }Implementations§
Source§impl WebRoute
impl WebRoute
Sourcepub fn join<R: ToSegments>(&self, route: R) -> Self
pub fn join<R: ToSegments>(&self, route: R) -> Self
Joins a route onto an existing WebRoute returning the joined route.
§Examples
use web_route::WebRoute;
let route = WebRoute::new("/some/route/{param}");
let nested_route = WebRoute::new("/a/nested/route");
let joined_route = route.join(&nested_route);
assert_eq!(joined_route, route.join("/a/nested/route"))Sourcepub fn as_template_route(&self) -> String
pub fn as_template_route(&self) -> String
Returns the route in its “templated” representation so that it can be used in web server route definitions.
§Examples
use web_route::WebRoute;
let route = WebRoute::new("/some/route/{param}");
let template_route = route.as_template_route();
assert_eq!(template_route, "/some/route/{param}")Sourcepub fn as_populated_route<V: Serialize>(
&self,
values: &V,
) -> Result<String, WebRouteError>
pub fn as_populated_route<V: Serialize>( &self, values: &V, ) -> Result<String, WebRouteError>
Attempts to populate the parameters of the route with their values.
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::WebRoute;
#[derive(serde::Serialize)]
struct RouteParams {
param: String,
}
let route = WebRoute::new("/some/route/{param}");
let populated_route = route
.as_populated_route(&RouteParams {
param: "value".to_owned(),
})
.unwrap();
assert_eq!(populated_route, "/some/route/value")Trait Implementations§
Source§impl<'de> Deserialize<'de> for WebRoute
impl<'de> Deserialize<'de> for WebRoute
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for WebRoute
Auto Trait Implementations§
impl Freeze for WebRoute
impl RefUnwindSafe for WebRoute
impl Send for WebRoute
impl Sync for WebRoute
impl Unpin for WebRoute
impl UnwindSafe for WebRoute
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