@@ -3,6 +3,7 @@ use std::fmt;
33use std:: str:: FromStr ;
44
55use 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 ) ]
2021pub struct ProjectId ( u64 ) ;
2122
2223impl 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-
4843macro_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) ]
10497mod 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