1use crate::WebUrl;
2
3impl WebUrl {
4 pub fn port(&self) -> Option<u16> {
8 self.port
9 }
10}
11
12#[cfg(test)]
13mod tests {
14 use crate::WebUrl;
15 use std::error::Error;
16 use std::str::FromStr;
17
18 #[test]
19 fn port_present() -> Result<(), Box<dyn Error>> {
20 let url = WebUrl::from_str("https://example.com:8080")?;
21 assert_eq!(url.port(), Some(8080));
22 Ok(())
23 }
24
25 #[test]
26 fn port_absent() -> Result<(), Box<dyn Error>> {
27 let url = WebUrl::from_str("https://example.com")?;
28 assert_eq!(url.port(), None);
29 Ok(())
30 }
31}