Created
December 15, 2019 23:16
-
-
Save dbrgn/01728c347edbf6fdb5545e99fbd91cdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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