1pub use crate::tokenizers::value::Tokenizer;
6
7#[derive(Debug, PartialEq, Eq, Ord, PartialOrd, Clone)]
10pub struct Uri(String);
11
12impl Uri {
13 pub fn new(uri: String) -> Self {
14 Self(uri)
15 }
16
17 pub fn value(&self) -> &str {
18 &self.0
19 }
20}
21
22impl From<Uri> for String {
23 fn from(uri: Uri) -> Self {
24 uri.0
25 }
26}
27
28impl From<String> for Uri {
29 fn from(uri: String) -> Self {
30 Self(uri)
31 }
32}
33
34impl<'a> From<Tokenizer<'a, 'u'>> for Uri {
35 fn from(tokenizer: Tokenizer<'a, 'u'>) -> Self {
36 Self(tokenizer.value.into())
37 }
38}
39
40impl std::fmt::Display for Uri {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(f, "u={}", self.value())
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn from_tokenizer1() {
52 let tokenizer: Tokenizer<'u'> = "http://www.jdoe.example.com/home.html".into();
53
54 assert_eq!(
55 Uri::from(tokenizer),
56 Uri("http://www.jdoe.example.com/home.html".into())
57 );
58 }
59
60 #[test]
61 fn display1() {
62 let uri = Uri::new("https://televiska.com".into());
63
64 assert_eq!(uri.to_string(), "u=https://televiska.com");
65 }
66}