refactor(status): deprecate StatusClass

This commit is contained in:
Sean McArthur
2017-05-11 12:46:46 -07:00
parent ae09d99375
commit 638582fae2

View File

@@ -449,6 +449,8 @@ impl StatusCode {
}
/// Determine the class of a status code, based on its first digit.
#[deprecated(note = "StatusClass is going away. Use the is_<class>() methods instead.")]
#[allow(deprecated)]
pub fn class(&self) -> StatusClass {
match self.to_u16() {
100...199 => StatusClass::Informational,
@@ -461,31 +463,37 @@ impl StatusCode {
}
/// Check if class is Informational.
#[allow(deprecated)]
pub fn is_informational(&self) -> bool {
self.class() == StatusClass::Informational
}
/// Check if class is Success.
#[allow(deprecated)]
pub fn is_success(&self) -> bool {
self.class() == StatusClass::Success
}
/// Check if class is Redirection.
#[allow(deprecated)]
pub fn is_redirection(&self) -> bool {
self.class() == StatusClass::Redirection
}
/// Check if class is ClientError.
#[allow(deprecated)]
pub fn is_client_error(&self) -> bool {
self.class() == StatusClass::ClientError
}
/// Check if class is ServerError.
#[allow(deprecated)]
pub fn is_server_error(&self) -> bool {
self.class() == StatusClass::ServerError
}
/// Check if class is NoClass
#[allow(deprecated)]
pub fn is_strange_status(&self) -> bool {
self.class() == StatusClass::NoClass
}
@@ -582,6 +590,7 @@ impl From<StatusCode> for u16 {
/// This can be used in cases where a status codes meaning is unknown, also,
/// to get the appropriate *category* of status.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
#[deprecated(note = "StatusClass is going away. Use the StatusCode::is_<class>() methods instead.")]
pub enum StatusClass {
/// 1xx (Informational): The request was received, continuing process
Informational,
@@ -602,6 +611,7 @@ pub enum StatusClass {
NoClass,
}
#[allow(deprecated)]
impl StatusClass {
/// Get the default status code for the class.
///
@@ -672,6 +682,7 @@ mod tests {
// - status code
// - default code (for the given status code)
// - canonical reason
#[allow(deprecated)]
fn validate(num: u16, status_code: StatusCode, default_code: StatusCode, reason: Option<&str>) {
assert_eq!(StatusCode::from_u16(num), status_code);
assert_eq!(status_code.to_u16(), num);