11//! HTTP RequestUris
2+ use std:: fmt:: { Display , self } ;
23use std:: str:: FromStr ;
34use url:: Url ;
45use url:: ParseError as UrlError ;
@@ -72,6 +73,17 @@ impl FromStr for RequestUri {
7273 }
7374}
7475
76+ impl Display for RequestUri {
77+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
78+ match * self {
79+ RequestUri :: AbsolutePath ( ref path) => f. write_str ( path) ,
80+ RequestUri :: AbsoluteUri ( ref url) => write ! ( f, "{}" , url) ,
81+ RequestUri :: Authority ( ref path) => f. write_str ( path) ,
82+ RequestUri :: Star => f. write_str ( "*" )
83+ }
84+ }
85+ }
86+
7587#[ test]
7688fn test_uri_fromstr ( ) {
7789 fn read ( s : & str , result : RequestUri ) {
@@ -83,3 +95,16 @@ fn test_uri_fromstr() {
8395 read ( "hyper.rs" , RequestUri :: Authority ( "hyper.rs" . to_owned ( ) ) ) ;
8496 read ( "/" , RequestUri :: AbsolutePath ( "/" . to_owned ( ) ) ) ;
8597}
98+
99+ #[ test]
100+ fn test_uri_display ( ) {
101+ fn assert_display ( expected_string : & str , request_uri : RequestUri ) {
102+ assert_eq ! ( expected_string, format!( "{}" , request_uri) ) ;
103+ }
104+
105+ assert_display ( "*" , RequestUri :: Star ) ;
106+ assert_display ( "http://hyper.rs/" , RequestUri :: AbsoluteUri ( Url :: parse ( "http://hyper.rs/" ) . unwrap ( ) ) ) ;
107+ assert_display ( "hyper.rs" , RequestUri :: Authority ( "hyper.rs" . to_owned ( ) ) ) ;
108+ assert_display ( "/" , RequestUri :: AbsolutePath ( "/" . to_owned ( ) ) ) ;
109+
110+ }
0 commit comments