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