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
macro_rules! gw2rs_id_generic {
($name: ident) => {
impl AsRef<$name> for $name {
fn as_ref(&self) -> &Self {
self
}
}
impl ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
::std::fmt::Display::fmt(&self.0, f)
}
}
};
}
macro_rules! gw2rs_id_u64 {
($name: ident) => {
#[allow(missing_docs)]
#[derive(Copy, Clone, Default, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct $name(pub u64);
gw2rs_id_generic!($name);
impl From<u64> for $name {
fn from(id_as_u64: u64) -> $name {
$name(id_as_u64)
}
}
impl From<$name> for u64 {
fn from(id_as_newtype: $name) -> u64 {
id_as_newtype.0
}
}
};
}
macro_rules! gw2rs_id_string {
($name: ident) => {
#[allow(missing_docs)]
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct $name(pub String);
gw2rs_id_generic!($name);
impl<T: AsRef<str>> From<T> for $name {
fn from(v: T) -> $name {
$name(String::from(v.as_ref()))
}
}
};
}