pub trait FromParam: Sized {
// Required method
fn from_param(value: &str) -> Result<Self, FrameworkError>;
}Expand description
Trait for types that can be extracted from a single path parameter
This trait enables automatic extraction of typed values from route parameters
like /users/{id} where {id} can be extracted as an i32.
§Example
The #[handler] macro uses this trait to transform:
ⓘ
#[handler]
pub async fn show(id: i32, slug: String) -> Response {
// ...
}Into code that extracts id and slug from the route parameters.
Required Methods§
Sourcefn from_param(value: &str) -> Result<Self, FrameworkError>
fn from_param(value: &str) -> Result<Self, FrameworkError>
Extract Self from a string parameter value
Returns Err(FrameworkError) if extraction fails, which will be
converted to an appropriate HTTP error response (400 Bad Request).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.