Skip to content

Instantly share code, notes, and snippets.

@dbrgn
Created December 15, 2019 23:16
Show Gist options
  • Save dbrgn/01728c347edbf6fdb5545e99fbd91cdc to your computer and use it in GitHub Desktop.
Save dbrgn/01728c347edbf6fdb5545e99fbd91cdc to your computer and use it in GitHub Desktop.
/// The result of a form validation: Either a successful redirect, or a
/// template response with an error status.
///
/// TODO: Generalize this and move it into a helper module.
pub enum ValidationResult {
Success(Redirect),
Invalid(Template, Status)
}
impl<'r> response::Responder<'r> for ValidationResult {
fn respond_to(self, req: &Request) -> response::Result<'r> {
match self {
ValidationResult::Success(redirect) => redirect.respond_to(req),
ValidationResult::Invalid(template, status) => {
template.respond_to(req).map(|mut response| {
response.set_status(status);
response
})
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment