@@ -44,6 +44,20 @@ impl<'dt, I: Indexed> Deserialize<'dt> for Column<I> {
4444 }
4545}
4646
47+ #[ cfg( feature = "serialize-rustc" ) ]
48+ impl < I : Indexed > rustc_serialize:: Decodable for Column < I > {
49+ fn decode < D : rustc_serialize:: Decoder > ( d : & mut D ) -> Result < Column < I > , D :: Error > {
50+ d. read_u32 ( ) . map ( Column :: new)
51+ }
52+ }
53+
54+ #[ cfg( feature = "serialize-rustc" ) ]
55+ impl < I : Indexed > rustc_serialize:: Encodable for Column < I > {
56+ fn encode < S : rustc_serialize:: Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
57+ s. emit_u32 ( self . 0 )
58+ }
59+ }
60+
4761impl Column < OneIndexed > {
4862 pub fn new_one_indexed ( c : u32 ) -> Column < OneIndexed > {
4963 Column ( c, PhantomData )
@@ -93,6 +107,20 @@ impl<'dt, I: Indexed> serde::Deserialize<'dt> for Row<I> {
93107 }
94108}
95109
110+ #[ cfg( feature = "serialize-rustc" ) ]
111+ impl < I : Indexed > rustc_serialize:: Decodable for Row < I > {
112+ fn decode < D : rustc_serialize:: Decoder > ( d : & mut D ) -> Result < Row < I > , D :: Error > {
113+ d. read_u32 ( ) . map ( Row :: new)
114+ }
115+ }
116+
117+ #[ cfg( feature = "serialize-rustc" ) ]
118+ impl < I : Indexed > rustc_serialize:: Encodable for Row < I > {
119+ fn encode < S : rustc_serialize:: Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
120+ s. emit_u32 ( self . 0 )
121+ }
122+ }
123+
96124impl Row < OneIndexed > {
97125 pub fn new_one_indexed ( c : u32 ) -> Row < OneIndexed > {
98126 Row ( c, PhantomData )
@@ -114,6 +142,7 @@ impl Row<ZeroIndexed> {
114142}
115143
116144#[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
145+ #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
117146#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
118147pub struct Position < I : Indexed > {
119148 pub row : Row < I > ,
@@ -147,6 +176,7 @@ impl Position<ZeroIndexed> {
147176}
148177
149178#[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
179+ #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
150180#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
151181pub struct Range < I : Indexed > {
152182 pub row_start : Row < I > ,
@@ -209,6 +239,7 @@ impl Range<ZeroIndexed> {
209239}
210240
211241#[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
242+ #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
212243#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
213244pub struct Location < I : Indexed > {
214245 pub file : PathBuf ,
@@ -244,6 +275,7 @@ impl Location<ZeroIndexed> {
244275}
245276
246277#[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
278+ #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
247279#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
248280pub struct Span < I : Indexed > {
249281 pub file : PathBuf ,
@@ -295,11 +327,13 @@ impl Span<ZeroIndexed> {
295327pub trait Indexed { }
296328
297329#[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
330+ #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
298331#[ derive( Hash , PartialEq , Eq , Debug , PartialOrd , Ord ) ]
299332pub struct ZeroIndexed ;
300333impl Indexed for ZeroIndexed { }
301334
302335#[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
336+ #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
303337#[ derive( Hash , PartialEq , Eq , Debug , PartialOrd , Ord ) ]
304338pub struct OneIndexed ;
305339impl Indexed for OneIndexed { }
0 commit comments