1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
use response::ClientResponse; pub use reqwest::StatusCode; pub trait Status { type OfType; fn of(&Option<&Self::OfType>) -> Self; fn is_ok(&self) -> bool; fn is_err(&self) -> bool; } impl<'a> Status for StatusCode { type OfType = ClientResponse; fn of(response: &Option<&Self::OfType>) -> Self { match *response { Some(r) => *r.status(), None => Self::from_u16(520), } } fn is_ok(&self) -> bool { self.is_success() || self.is_informational() || self.is_redirection() } fn is_err(&self) -> bool { !self.is_ok() } }