pub struct Route { /* private fields */ }Expand description
Represents a route definition that can be registered with .mount()
Implementations§
Source§impl Route
impl Route
Sourcepub fn new<H, T>(path: &'static str, method: &'static str, handler: H) -> Routewhere
H: Handler<T>,
T: 'static,
pub fn new<H, T>(path: &'static str, method: &'static str, handler: H) -> Routewhere
H: Handler<T>,
T: 'static,
Create a new route from a handler with path and method
Sourcepub fn description(self, description: impl Into<String>) -> Route
pub fn description(self, description: impl Into<String>) -> Route
Set the operation description
Sourcepub fn param(
self,
name: impl Into<String>,
schema_type: impl Into<String>,
) -> Route
pub fn param( self, name: impl Into<String>, schema_type: impl Into<String>, ) -> Route
Set a custom OpenAPI schema type for a path parameter
This is useful for overriding the auto-inferred type, e.g., when
a parameter named id is actually a UUID instead of an integer.
§Supported schema types
"uuid"- String with UUID format"integer"or"int"- Integer with int64 format"string"- Plain string"boolean"or"bool"- Boolean"number"- Number (float)
§Example
ⓘ
#[rustapi::get("/users/{id}")]
async fn get_user(Path(id): Path<Uuid>) -> Json<User> {
// ...
}
// In route registration:
get_route("/users/{id}", get_user).param("id", "uuid")Sourcepub fn param_schemas(&self) -> &HashMap<String, String>
pub fn param_schemas(&self) -> &HashMap<String, String>
Get the custom parameter schemas
Auto Trait Implementations§
impl Freeze for Route
impl !RefUnwindSafe for Route
impl Send for Route
impl Sync for Route
impl Unpin for Route
impl !UnwindSafe for Route
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more