pub trait AutoRouteBinding: Sized + Send {
// Required method
fn from_route_param<'life0, 'async_trait>(
value: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, FrameworkError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for automatic route model binding
This trait is automatically implemented for all SeaORM models whose Entity
implements ferro_rs::database::Model. You don’t need to implement this manually.
Unlike RouteBinding, this trait doesn’t require a param_name() method.
The parameter name is derived from the handler function signature.
§Example
// Just use Model in handler - binding is automatic!
#[handler]
pub async fn show(user: user::Model) -> Response {
json_response!({ "name": user.name })
}Required Methods§
Sourcefn from_route_param<'life0, 'async_trait>(
value: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, FrameworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn from_route_param<'life0, 'async_trait>(
value: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, FrameworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Fetch the model from the database using the route parameter value
This method parses the parameter as the primary key type and fetches the corresponding model from the database.
§Returns
Ok(Self)- The model was foundErr(FrameworkError::ModelNotFound)- Model not found (returns 404)Err(FrameworkError::ParamParse)- Parameter could not be parsed (returns 400)
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.
Implementors§
impl<M, E> AutoRouteBinding for Mwhere
M: SeaModelTrait<Entity = E> + Send + Sync,
E: EntityTrait<Model = M> + Model + Sync,
E::PrimaryKey: PrimaryKeyTrait,
<E::PrimaryKey as PrimaryKeyTrait>::ValueType: FromStr + Send,
Blanket implementation of AutoRouteBinding for all SeaORM models
This automatically implements route model binding for any SeaORM Model type
whose Entity implements ferro_rs::database::Model. Supports any primary key type
that implements FromStr (i32, i64, String, UUID, etc.).