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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::internal::Sealed;
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 {
pub fn as_ref(&self) -> Ref<'_> {
Ref(&self.0)
}
}
impl<'a> Ref<'a> {
pub fn to_owned(&self) -> Id {
Id(self.0.into())
}
}
impl From<String> for Id {
fn from(id: String) -> Self {
Self(id)
}
}
impl<'a> From<&'a str> for Ref<'a> {
fn from(id: &'a str) -> Self {
Self(id)
}
}
impl<'a> PartialEq<Ref<'a>> for Id {
fn eq(&self, other: &Ref<'a>) -> bool {
self.0 == other.0
}
}
impl<'a> PartialEq<Id> for Ref<'a> {
fn eq(&self, other: &Id) -> bool {
self.0 == other.0
}
}
impl Sealed for Id {}
impl Sealed for Ref<'_> {}
#[allow(clippy::module_name_repetitions)]
pub trait AsFileId: Sealed {
#[doc(hidden)]
fn as_file_id(&self) -> Ref<'_>;
}
impl AsFileId for Id {
fn as_file_id(&self) -> Ref<'_> {
self.as_ref()
}
}
impl AsFileId for Ref<'_> {
fn as_file_id(&self) -> Ref<'_> {
*self
}
}