Skip to content

Commit 1a2cf3a

Browse files
authored
Merge pull request #14 from sfackler/method-display
Implement Display for Method
2 parents 22a6372 + 19e4348 commit 1a2cf3a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::io::prelude::*;
44
use std::collections::HashMap;
55
use std::error::Error;
66
use std::net::SocketAddr;
7+
use std::fmt;
78

89
pub use self::typemap::TypeMap;
910
mod typemap;
@@ -39,6 +40,25 @@ pub enum Method {
3940
Other(String)
4041
}
4142

43+
impl fmt::Display for Method {
44+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
45+
let s = match *self {
46+
Method::Get => "GET",
47+
Method::Post => "POST",
48+
Method::Put => "POST",
49+
Method::Delete => "DELETE",
50+
Method::Head => "HEAD",
51+
Method::Connect => "CONNECT",
52+
Method::Options => "OPTIONS",
53+
Method::Trace => "TRACE",
54+
Method::Patch => "PATCH",
55+
Method::Purge => "PURGE",
56+
Method::Other(ref s) => s,
57+
};
58+
fmt.write_str(s)
59+
}
60+
}
61+
4262
/// A Dictionary for extensions provided by the server or middleware
4363
pub type Extensions = TypeMap;
4464

0 commit comments

Comments
 (0)