2016-10-04 00:09:13 +00:00
|
|
|
use std::fmt;
|
2016-04-11 10:57:23 +00:00
|
|
|
|
|
|
|
use term_painter::Color::*;
|
|
|
|
use term_painter::ToStyle;
|
2016-10-04 00:09:13 +00:00
|
|
|
|
|
|
|
use http::hyper::FreshHyperResponse;
|
2016-04-11 10:57:23 +00:00
|
|
|
|
|
|
|
pub enum Outcome<'h> {
|
2016-09-22 01:23:44 +00:00
|
|
|
/// Signifies a response that completed sucessfully.
|
2016-04-11 10:57:23 +00:00
|
|
|
Complete,
|
2016-09-22 01:31:26 +00:00
|
|
|
/// Signifies a response that failed internally.
|
2016-09-30 04:44:27 +00:00
|
|
|
Bad(FreshHyperResponse<'h>),
|
2016-09-22 01:23:44 +00:00
|
|
|
/// Signifies a failing response where no further processing should happen.
|
2016-04-11 10:57:23 +00:00
|
|
|
FailStop,
|
2016-09-22 01:23:44 +00:00
|
|
|
/// Signifies a failing response whose request should be processed further.
|
2016-09-30 04:44:27 +00:00
|
|
|
FailForward(FreshHyperResponse<'h>),
|
2016-04-11 10:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'h> Outcome<'h> {
|
|
|
|
pub fn as_str(&self) -> &'static str {
|
2016-04-23 02:48:03 +00:00
|
|
|
match *self {
|
|
|
|
Outcome::Complete => "Complete",
|
|
|
|
Outcome::FailStop => "FailStop",
|
2016-09-22 01:31:26 +00:00
|
|
|
Outcome::Bad(..) => "Bad",
|
2016-04-23 02:48:03 +00:00
|
|
|
Outcome::FailForward(..) => "FailForward",
|
2016-04-11 10:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_int(&self) -> isize {
|
2016-04-23 02:48:03 +00:00
|
|
|
match *self {
|
|
|
|
Outcome::Complete => 0,
|
2016-09-22 01:31:26 +00:00
|
|
|
Outcome::Bad(..) => 1,
|
2016-09-22 01:23:44 +00:00
|
|
|
Outcome::FailStop => 2,
|
|
|
|
Outcome::FailForward(..) => 3,
|
2016-04-11 10:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'h> PartialEq for Outcome<'h> {
|
|
|
|
fn eq(&self, other: &Outcome<'h>) -> bool {
|
|
|
|
self.as_int() == other.as_int()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'h> fmt::Debug for Outcome<'h> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "Outcome::{}", self.as_str())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'h> fmt::Display for Outcome<'h> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-04-23 02:48:03 +00:00
|
|
|
match *self {
|
2016-09-30 22:20:11 +00:00
|
|
|
Outcome::Complete => write!(f, "{}", Green.paint("Complete")),
|
|
|
|
Outcome::Bad(..) => write!(f, "{}", Yellow.paint("Bad Completion")),
|
|
|
|
Outcome::FailStop => write!(f, "{}", Red.paint("Failed")),
|
|
|
|
Outcome::FailForward(..) => write!(f, "{}", Cyan.paint("Forwarding")),
|
2016-04-11 10:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|