oni_comb_uri_rs/models/
hier_part.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::models::authority::Authority;
use crate::models::path::Path;

use std::fmt::Formatter;

#[derive(Debug, Clone, PartialEq, Hash)]
pub struct HierPart {
  pub(crate) authority: Option<Authority>,
  pub(crate) path: Path,
}

impl std::fmt::Display for HierPart {
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    write!(
      f,
      "{}{}",
      self
        .authority
        .as_ref()
        .map(|e| format!("//{}", e.to_string()))
        .unwrap_or("".to_string()),
      self.path.to_string()
    )
  }
}

impl HierPart {
  pub fn new(authority: Option<Authority>, path: Path) -> HierPart {
    HierPart { authority, path }
  }

  pub fn of_path(path: Path) -> HierPart {
    HierPart { authority: None, path }
  }
}

impl Default for HierPart {
  fn default() -> HierPart {
    HierPart {
      authority: None,
      path: Path::default(),
    }
  }
}