uri_rs/ast/
scheme.rs

1use std::fmt::Formatter;
2
3use crate::parser::parsers::Elms;
4
5#[derive(Debug, Clone, PartialEq, Hash)]
6pub struct Scheme(String);
7
8impl Default for Scheme {
9  fn default() -> Self {
10    Scheme(String::default())
11  }
12}
13
14impl std::fmt::Display for Scheme {
15  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16    write!(f, "{}", self.0)
17  }
18}
19
20impl From<String> for Scheme {
21  fn from(src: String) -> Self {
22    Self(src)
23  }
24}
25
26impl From<&str> for Scheme {
27  fn from(src: &str) -> Self {
28    Self(src.to_string())
29  }
30}
31
32impl From<&[u8]> for Scheme {
33  fn from(src: &[u8]) -> Self {
34    Self(String::from_utf8(src.to_vec()).unwrap())
35  }
36}
37
38impl From<Elms<'_>> for Scheme {
39  fn from(src: Elms) -> Self {
40    Self(src.as_string().unwrap())
41  }
42}
43
44impl Scheme {
45  pub fn new(value: String) -> Self {
46    Self(value)
47  }
48}