use actix_web::http::header::IntoHeaderValue; use actix_web::HttpResponse; use std::fmt::{Debug, Display}; use std::str::FromStr; pub fn redirect(path: impl IntoHeaderValue) -> actix_web::Result { Ok(HttpResponse::SeeOther() .header("location", path) // back - to where? .finish()) } pub trait ParseOrBadReq { fn parse_or_bad_request(&self) -> actix_web::Result where T: FromStr, E: Display + Debug + 'static; } impl ParseOrBadReq for &str { fn parse_or_bad_request(&self) -> actix_web::Result where T: FromStr, E: Display + Debug + 'static, { self.parse::().map_err(|e| { error!("Parse error for \"{}\"", self); actix_web::error::ErrorBadRequest(e) }) } } impl ParseOrBadReq for String { fn parse_or_bad_request(&self) -> actix_web::Result where T: FromStr, E: Display + Debug + 'static, { self.as_str().parse_or_bad_request() } }