File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -75,21 +75,38 @@ mod serde {
7575 }
7676 }
7777}
78- impl std:: fmt:: Display for Version {
79- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
80- f. write_str ( match self {
78+
79+ impl AsRef < str > for Version {
80+ fn as_ref ( & self ) -> & ' static str {
81+ match self {
8182 Version :: Http0_9 => "HTTP/0.9" ,
8283 Version :: Http1_0 => "HTTP/1.0" ,
8384 Version :: Http1_1 => "HTTP/1.1" ,
8485 Version :: Http2_0 => "HTTP/2" ,
8586 Version :: Http3_0 => "HTTP/3" ,
86- } )
87+ }
88+ }
89+ }
90+
91+ impl std:: fmt:: Display for Version {
92+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
93+ f. write_str ( self . as_ref ( ) )
8794 }
8895}
8996
9097#[ cfg( test) ]
9198mod test {
9299 use super :: * ;
100+
101+ #[ test]
102+ fn as_ref ( ) {
103+ assert_eq ! ( Version :: Http0_9 . as_ref( ) , "HTTP/0.9" ) ;
104+ assert_eq ! ( Version :: Http1_0 . as_ref( ) , "HTTP/1.0" ) ;
105+ assert_eq ! ( Version :: Http1_1 . as_ref( ) , "HTTP/1.1" ) ;
106+ assert_eq ! ( Version :: Http2_0 . as_ref( ) , "HTTP/2" ) ;
107+ assert_eq ! ( Version :: Http3_0 . as_ref( ) , "HTTP/3" ) ;
108+ }
109+
93110 #[ test]
94111 fn to_string ( ) {
95112 let output = format ! (
You can’t perform that action at this time.
0 commit comments