request
创建提取器,hander里可以直接使用
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection
where
ConnectionPool: FromRef<S>,
S: Send + Sync,
{
type Rejection = (StatusCode, String);
async fn from_request_parts(_parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let pool = ConnectionPool::from_ref(state);
let conn = pool.get_owned().await.map_err(internal_error)?;
Ok(Self(conn))
}
}