1- // Copyright 2016 The RLS Project Developers.
2- //
3- // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4- // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5- // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6- // option. This file may not be copied, modified, or distributed
7- // except according to those terms.
8-
9- #![ cfg_attr( rustbuild, feature( staged_api, rustc_private) ) ]
10- #![ cfg_attr( rustbuild, unstable( feature = "rustc_private" , issue = "27812" ) ) ]
11-
12- #[ cfg( feature = "serialize-serde" ) ]
131extern crate serde;
14- #[ cfg( feature = "serialize-serde " ) ]
2+ #[ cfg( feature = "derive " ) ]
153#[ macro_use]
164extern crate serde_derive;
17- #[ cfg( feature = "serialize-rustc" ) ]
18- extern crate rustc_serialize;
195
20- #[ cfg( feature = "serialize-rustc" ) ]
21- use rustc_serialize:: { Decodable , Encodable } ;
22- #[ cfg( feature = "serialize-serde" ) ]
236use serde:: { Deserialize , Serialize } ;
247
258use std:: marker:: PhantomData ;
269use std:: path:: PathBuf ;
2710
2811pub mod compiler;
12+ mod serde_expanded;
2913
3014#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
3115pub struct Column < I : Indexed > ( pub u32 , PhantomData < I > ) ;
@@ -44,7 +28,6 @@ impl<I: Indexed> Clone for Column<I> {
4428
4529impl < I : Indexed > Copy for Column < I > { }
4630
47- #[ cfg( feature = "serialize-serde" ) ]
4831impl < I : Indexed > Serialize for Column < I > {
4932 fn serialize < S : serde:: Serializer > (
5033 & self ,
@@ -54,26 +37,11 @@ impl<I: Indexed> Serialize for Column<I> {
5437 }
5538}
5639
57- #[ cfg( feature = "serialize-serde" ) ]
5840impl < ' dt , I : Indexed > Deserialize < ' dt > for Column < I > {
5941 fn deserialize < D : serde:: Deserializer < ' dt > > (
6042 d : D ,
6143 ) -> std:: result:: Result < Self , <D as serde:: Deserializer < ' dt > >:: Error > {
62- <u32 as Deserialize >:: deserialize ( d) . map ( |x| Column :: new ( x) )
63- }
64- }
65-
66- #[ cfg( feature = "serialize-rustc" ) ]
67- impl < I : Indexed > Decodable for Column < I > {
68- fn decode < D : rustc_serialize:: Decoder > ( d : & mut D ) -> Result < Column < I > , D :: Error > {
69- d. read_u32 ( ) . map ( |x| Column :: new ( x) )
70- }
71- }
72-
73- #[ cfg( feature = "serialize-rustc" ) ]
74- impl < I : Indexed > Encodable for Column < I > {
75- fn encode < S : rustc_serialize:: Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
76- s. emit_u32 ( self . 0 )
44+ <u32 as Deserialize >:: deserialize ( d) . map ( Column :: new)
7745 }
7846}
7947
@@ -114,31 +82,15 @@ impl<I: Indexed> Clone for Row<I> {
11482
11583impl < I : Indexed > Copy for Row < I > { }
11684
117- #[ cfg( feature = "serialize-serde" ) ]
11885impl < I : Indexed > serde:: Serialize for Row < I > {
11986 fn serialize < S : serde:: Serializer > ( & self , s : S ) -> Result < S :: Ok , S :: Error > {
12087 s. serialize_u32 ( self . 0 )
12188 }
12289}
12390
124- #[ cfg( feature = "serialize-serde" ) ]
12591impl < ' dt , I : Indexed > serde:: Deserialize < ' dt > for Row < I > {
12692 fn deserialize < D : serde:: Deserializer < ' dt > > ( d : D ) -> std:: result:: Result < Self , D :: Error > {
127- <u32 as Deserialize >:: deserialize ( d) . map ( |x| Row :: new ( x) )
128- }
129- }
130-
131- #[ cfg( feature = "serialize-rustc" ) ]
132- impl < I : Indexed > Decodable for Row < I > {
133- fn decode < D : rustc_serialize:: Decoder > ( d : & mut D ) -> Result < Row < I > , D :: Error > {
134- d. read_u32 ( ) . map ( |x| Row :: new ( x) )
135- }
136- }
137-
138- #[ cfg( feature = "serialize-rustc" ) ]
139- impl < I : Indexed > Encodable for Row < I > {
140- fn encode < S : rustc_serialize:: Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
141- s. emit_u32 ( self . 0 )
93+ <u32 as Deserialize >:: deserialize ( d) . map ( Row :: new)
14294 }
14395}
14496
@@ -162,8 +114,7 @@ impl Row<ZeroIndexed> {
162114 }
163115}
164116
165- #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
166- #[ cfg_attr( feature = "serialize-serde" , derive( Serialize , Deserialize ) ) ]
117+ #[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
167118#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
168119pub struct Position < I : Indexed > {
169120 pub row : Row < I > ,
@@ -196,8 +147,7 @@ impl Position<ZeroIndexed> {
196147 }
197148}
198149
199- #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
200- #[ cfg_attr( feature = "serialize-serde" , derive( Serialize , Deserialize ) ) ]
150+ #[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
201151#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
202152pub struct Range < I : Indexed > {
203153 pub row_start : Row < I > ,
@@ -259,8 +209,7 @@ impl Range<ZeroIndexed> {
259209 }
260210}
261211
262- #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
263- #[ cfg_attr( feature = "serialize-serde" , derive( Serialize , Deserialize ) ) ]
212+ #[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
264213#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
265214pub struct Location < I : Indexed > {
266215 pub file : PathBuf ,
@@ -295,8 +244,7 @@ impl Location<ZeroIndexed> {
295244 }
296245}
297246
298- #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
299- #[ cfg_attr( feature = "serialize-serde" , derive( Serialize , Deserialize ) ) ]
247+ #[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
300248#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
301249pub struct Span < I : Indexed > {
302250 pub file : PathBuf ,
@@ -345,17 +293,14 @@ impl Span<ZeroIndexed> {
345293 }
346294}
347295
348- #[ cfg( feature = "serialize-serde" ) ]
349296pub trait Indexed { }
350- #[ cfg( not( feature = "serialize-serde" ) ) ]
351- pub trait Indexed { }
352- #[ cfg_attr( feature = "serialize-rustc" , derive( RustcDecodable , RustcEncodable ) ) ]
353- #[ cfg_attr( feature = "serialize-serde" , derive( Serialize , Deserialize ) ) ]
297+
298+ #[ cfg_attr( feature = "derive" , derive( Serialize , Deserialize ) ) ]
354299#[ derive( Hash , PartialEq , Eq , Debug , PartialOrd , Ord ) ]
355300pub struct ZeroIndexed ;
356301impl Indexed for ZeroIndexed { }
357- # [ cfg_attr ( feature = "serialize-rustc" , derive ( RustcDecodable , RustcEncodable ) ) ]
358- #[ cfg_attr( feature = "serialize-serde " , derive( Serialize , Deserialize ) ) ]
302+
303+ #[ cfg_attr( feature = "derive " , derive( Serialize , Deserialize ) ) ]
359304#[ derive( Hash , PartialEq , Eq , Debug , PartialOrd , Ord ) ]
360305pub struct OneIndexed ;
361306impl Indexed for OneIndexed { }
0 commit comments