1use crate::{Path, WebUrl};
2
3impl WebUrl {
4 pub fn path(&self) -> Path<'_> {
8 unsafe { Path::new(self.path_str()) }
9 }
10
11 fn path_str(&self) -> &str {
15 let start: usize = self.port_end as usize;
16 let end: usize = self.path_end as usize;
17 &self.url[start..end]
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use crate::WebUrl;
24 use std::error::Error;
25 use std::str::FromStr;
26
27 #[test]
28 fn path_explicit() -> Result<(), Box<dyn Error>> {
29 let url = WebUrl::from_str("https://example.com/the/path")?;
30 assert_eq!(url.path().as_str(), "/the/path");
31 Ok(())
32 }
33
34 #[test]
35 fn path_default() -> Result<(), Box<dyn Error>> {
36 let url = WebUrl::from_str("https://example.com")?;
37 assert_eq!(url.path().as_str(), "/");
38 Ok(())
39 }
40}