From 49b73ed2703a044e54e00b8a76f9b1f0bb0933dd Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Sun, 6 Sep 2020 17:30:05 -0700 Subject: [PATCH 1/2] impl Display for Version --- src/version.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/version.rs b/src/version.rs index 04103079..ff38d8b2 100644 --- a/src/version.rs +++ b/src/version.rs @@ -18,9 +18,34 @@ pub enum Version { Http3_0, } +impl std::fmt::Display for Version { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Version::Http0_9 => "HTTP/0.9", + Version::Http1_0 => "HTTP/1.0", + Version::Http1_1 => "HTTP/1.1", + Version::Http2_0 => "HTTP/2.0", + Version::Http3_0 => "HTTP/3.0", + }) + } +} + #[cfg(test)] mod test { use super::*; + #[test] + fn to_string() { + let output = format!( + "{} {} {} {} {}", + Version::Http0_9, + Version::Http1_0, + Version::Http1_1, + Version::Http2_0, + Version::Http3_0 + ); + assert_eq!("HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2.0 HTTP/3.0", output); + } + #[test] fn ord() { use Version::*; From 5e83e2e04a28b82afc595f9d90ae8e00cd9f654b Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 7 Sep 2020 10:38:30 -0700 Subject: [PATCH 2/2] no .0 for 2 and 3 --- src/version.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.rs b/src/version.rs index ff38d8b2..2616384b 100644 --- a/src/version.rs +++ b/src/version.rs @@ -24,8 +24,8 @@ impl std::fmt::Display for Version { Version::Http0_9 => "HTTP/0.9", Version::Http1_0 => "HTTP/1.0", Version::Http1_1 => "HTTP/1.1", - Version::Http2_0 => "HTTP/2.0", - Version::Http3_0 => "HTTP/3.0", + Version::Http2_0 => "HTTP/2", + Version::Http3_0 => "HTTP/3", }) } } @@ -43,7 +43,7 @@ mod test { Version::Http2_0, Version::Http3_0 ); - assert_eq!("HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2.0 HTTP/3.0", output); + assert_eq!("HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2 HTTP/3", output); } #[test]