1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::fmt::{self, Formatter};
use super::Url;
pub struct PathFormatter<'a, T:'a> {
    
    pub path: &'a [T]
}
impl<'a, T: fmt::Display> fmt::Display for PathFormatter<'a, T> {
    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
        if self.path.is_empty() {
            formatter.write_str("/")
        } else {
            for path_part in self.path {
                try!("/".fmt(formatter));
                try!(path_part.fmt(formatter));
            }
            Ok(())
        }
    }
}
pub struct UserInfoFormatter<'a> {
    
    pub username: &'a str,
    
    
    
    pub password: Option<&'a str>
}
impl<'a> fmt::Display for UserInfoFormatter<'a> {
    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
        if !self.username.is_empty() || self.password.is_some() {
            try!(formatter.write_str(self.username));
            if let Some(password) = self.password {
                try!(formatter.write_str(":"));
                try!(formatter.write_str(password));
            }
            try!(formatter.write_str("@"));
        }
        Ok(())
    }
}
pub struct UrlNoFragmentFormatter<'a> {
    pub url: &'a Url
}
impl<'a> fmt::Display for UrlNoFragmentFormatter<'a> {
    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
        try!(formatter.write_str(&self.url.scheme));
        try!(formatter.write_str(":"));
        try!(self.url.scheme_data.fmt(formatter));
        if let Some(ref query) = self.url.query {
            try!(formatter.write_str("?"));
            try!(formatter.write_str(query));
        }
        Ok(())
    }
}