1use std::fmt::{Display, Formatter};
2
3use crate::WebUrl;
4
5impl WebUrl {
6 pub fn as_str(&self) -> &str {
10 self.url.as_str()
11 }
12}
13
14impl AsRef<str> for WebUrl {
15 fn as_ref(&self) -> &str {
16 self.as_str()
17 }
18}
19
20impl Display for WebUrl {
21 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22 write!(f, "{}", self.url)
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use crate::WebUrl;
29 use std::error::Error;
30 use std::str::FromStr;
31
32 #[test]
33 fn display() -> Result<(), Box<dyn Error>> {
34 let url = WebUrl::from_str("https://example.com/path?query=1#frag")?;
35 assert_eq!(url.as_str(), "https://example.com/path?query=1#frag");
36 assert_eq!(url.as_ref(), "https://example.com/path?query=1#frag");
37 assert_eq!(url.to_string(), "https://example.com/path?query=1#frag");
38 Ok(())
39 }
40}