term_rustdoc/tree/id/
impls.rs

1use super::ID;
2use crate::util::XString;
3use std::{fmt, ops::Deref};
4
5impl Deref for ID {
6    type Target = str;
7
8    fn deref(&self) -> &Self::Target {
9        &self.id
10    }
11}
12
13impl fmt::Debug for ID {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        <str as fmt::Debug>::fmt(self, f)
16    }
17}
18
19impl fmt::Display for ID {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        <str as fmt::Display>::fmt(self, f)
22    }
23}
24
25impl From<&str> for ID {
26    fn from(s: &str) -> Self {
27        ID::new(s)
28    }
29}
30
31impl From<XString> for ID {
32    fn from(id: XString) -> Self {
33        ID { id }
34    }
35}
36
37impl From<ID> for XString {
38    fn from(id: ID) -> Self {
39        id.id
40    }
41}
42
43impl From<&ID> for XString {
44    fn from(id: &ID) -> Self {
45        id.id.clone()
46    }
47}
48
49impl ID {
50    pub fn new(s: &str) -> ID {
51        ID { id: s.into() }
52    }
53
54    pub fn as_str(&self) -> &str {
55        &self.id
56    }
57}