pub trait MapConstraintExt<T> {
// Required method
fn map_constraint(
self,
map: &ConstraintMap,
data: &Value,
url: impl Into<String>,
) -> Result<T, ActionError>;
}Expand description
Extension trait on Result<T, DbErr> for ergonomic call-site mapping.
Eliminates closure ladders at the write site: instead of chaining
.map_err(|e| map.try_map(e).map(...).unwrap_or_else(...)), use:
let page = new_page.insert(db).await
.map_constraint(&map, &data, "/pages/new")?;On a matching UNIQUE violation the ValidationError is flashed into the
session and an crate::http::action::ActionError configured to redirect
to url is returned (identical to the Phase 190 surfacing chain).
On any non-matching error, From<DbErr> for ActionError is applied —
the existing passthrough — so no error is ever swallowed.
Required Methods§
Sourcefn map_constraint(
self,
map: &ConstraintMap,
data: &Value,
url: impl Into<String>,
) -> Result<T, ActionError>
fn map_constraint( self, map: &ConstraintMap, data: &Value, url: impl Into<String>, ) -> Result<T, ActionError>
Map a DB UNIQUE-constraint violation to a field-level error and redirect.
See the trait documentation for full semantics.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".