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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize)]
#[serde(transparent)]
pub struct Id(pub String);
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize)]
#[serde(transparent)]
pub struct Ref<'a>(pub &'a str);
impl Id {
#[must_use]
pub fn as_ref(&self) -> Ref<'_> {
Ref(&self.0)
}
}
impl<'a> Ref<'a> {
#[must_use]
pub fn to_owned(&self) -> Id {
Id(self.0.into())
}
}
impl From<String> for Id {
#[must_use]
fn from(id: String) -> Self {
Self(id)
}
}
impl<'a> From<&'a str> for Ref<'a> {
#[must_use]
fn from(id: &'a str) -> Self {
Self(id)
}
}
impl<'a> PartialEq<Ref<'a>> for Id {
#[must_use]
fn eq(&self, other: &Ref<'a>) -> bool {
self.0 == other.0
}
}
impl<'a> PartialEq<Id> for Ref<'a> {
#[must_use]
fn eq(&self, other: &Id) -> bool {
self.0 == other.0
}
}