Skip to main content

haystack_core/kinds/
uri.rs

1use std::fmt;
2
3/// Universal Resource Identifier.
4/// Zinc: `` `http://example.com` ``
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct Uri(pub String);
7
8impl Uri {
9    pub fn new(val: impl Into<String>) -> Self {
10        Self(val.into())
11    }
12
13    pub fn val(&self) -> &str {
14        &self.0
15    }
16}
17
18impl fmt::Display for Uri {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        write!(f, "{}", self.0)
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn uri_display() {
30        let u = Uri::new("http://example.com");
31        assert_eq!(u.to_string(), "http://example.com");
32    }
33
34    #[test]
35    fn uri_equality() {
36        assert_eq!(Uri::new("http://a.com"), Uri::new("http://a.com"));
37        assert_ne!(Uri::new("http://a.com"), Uri::new("http://b.com"));
38    }
39
40    #[test]
41    fn uri_val() {
42        let u = Uri::new("http://example.com");
43        assert_eq!(u.val(), "http://example.com");
44    }
45}