pincer_core/
path_template.rs1#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18pub struct PathTemplate(&'static str);
19
20impl PathTemplate {
21 #[must_use]
23 pub const fn new(template: &'static str) -> Self {
24 Self(template)
25 }
26
27 #[must_use]
29 pub const fn as_str(&self) -> &'static str {
30 self.0
31 }
32}
33
34impl std::fmt::Display for PathTemplate {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 write!(f, "{}", self.0)
37 }
38}
39
40impl AsRef<str> for PathTemplate {
41 fn as_ref(&self) -> &str {
42 self.0
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn path_template_as_str() {
52 let template = PathTemplate::new("/users/{id}/posts/{post_id}");
53 assert_eq!(template.as_str(), "/users/{id}/posts/{post_id}");
54 }
55
56 #[test]
57 fn path_template_as_ref() {
58 let template = PathTemplate::new("/users/{id}");
59 let s: &str = template.as_ref();
60 assert_eq!(s, "/users/{id}");
61 }
62}