Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 62625db

Browse files
authored
fix(project_id): Serialize and deserialize as number (#45)
1 parent e41408e commit 62625db

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/project_id.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt;
33
use std::str::FromStr;
44

55
use failure::Fail;
6+
use serde::{Deserialize, Serialize};
67

78
/// Raised if a project ID cannot be parsed from a string.
89
#[derive(Debug, Fail, PartialEq, Eq, PartialOrd, Ord)]
@@ -16,7 +17,7 @@ pub enum ParseProjectIdError {
1617
}
1718

1819
/// Represents a project ID.
19-
#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
20+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
2021
pub struct ProjectId(u64);
2122

2223
impl ProjectId {
@@ -39,12 +40,6 @@ impl fmt::Display for ProjectId {
3940
}
4041
}
4142

42-
impl fmt::Debug for ProjectId {
43-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44-
write!(f, "{}", self.value())
45-
}
46-
}
47-
4843
macro_rules! impl_from {
4944
($ty:ty) => {
5045
impl From<$ty> for ProjectId {
@@ -98,8 +93,6 @@ impl FromStr for ProjectId {
9893
}
9994
}
10095

101-
impl_str_serde!(ProjectId);
102-
10396
#[cfg(test)]
10497
mod test {
10598
use super::*;
@@ -119,12 +112,9 @@ mod test {
119112
);
120113
assert_eq!(ProjectId::new(42).to_string(), "42");
121114

115+
assert_eq!(serde_json::to_string(&ProjectId::new(42)).unwrap(), "42");
122116
assert_eq!(
123-
serde_json::to_string(&ProjectId::new(42)).unwrap(),
124-
"\"42\""
125-
);
126-
assert_eq!(
127-
serde_json::from_str::<ProjectId>("\"42\"").unwrap(),
117+
serde_json::from_str::<ProjectId>("42").unwrap(),
128118
ProjectId::new(42)
129119
);
130120
}

0 commit comments

Comments
 (0)