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" ) ]
13
1
extern crate serde;
14
- #[ cfg( feature = "serialize-serde " ) ]
2
+ #[ cfg( feature = "derive " ) ]
15
3
#[ macro_use]
16
4
extern crate serde_derive;
17
- #[ cfg( feature = "serialize-rustc" ) ]
18
- extern crate rustc_serialize;
19
5
20
- #[ cfg( feature = "serialize-rustc" ) ]
21
- use rustc_serialize:: { Decodable , Encodable } ;
22
- #[ cfg( feature = "serialize-serde" ) ]
23
6
use serde:: { Deserialize , Serialize } ;
24
7
25
8
use std:: marker:: PhantomData ;
26
9
use std:: path:: PathBuf ;
27
10
28
11
pub mod compiler;
12
+ mod serde_expanded;
29
13
30
14
#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
31
15
pub struct Column < I : Indexed > ( pub u32 , PhantomData < I > ) ;
@@ -44,7 +28,6 @@ impl<I: Indexed> Clone for Column<I> {
44
28
45
29
impl < I : Indexed > Copy for Column < I > { }
46
30
47
- #[ cfg( feature = "serialize-serde" ) ]
48
31
impl < I : Indexed > Serialize for Column < I > {
49
32
fn serialize < S : serde:: Serializer > (
50
33
& self ,
@@ -54,26 +37,11 @@ impl<I: Indexed> Serialize for Column<I> {
54
37
}
55
38
}
56
39
57
- #[ cfg( feature = "serialize-serde" ) ]
58
40
impl < ' dt , I : Indexed > Deserialize < ' dt > for Column < I > {
59
41
fn deserialize < D : serde:: Deserializer < ' dt > > (
60
42
d : D ,
61
43
) -> 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)
77
45
}
78
46
}
79
47
@@ -114,31 +82,15 @@ impl<I: Indexed> Clone for Row<I> {
114
82
115
83
impl < I : Indexed > Copy for Row < I > { }
116
84
117
- #[ cfg( feature = "serialize-serde" ) ]
118
85
impl < I : Indexed > serde:: Serialize for Row < I > {
119
86
fn serialize < S : serde:: Serializer > ( & self , s : S ) -> Result < S :: Ok , S :: Error > {
120
87
s. serialize_u32 ( self . 0 )
121
88
}
122
89
}
123
90
124
- #[ cfg( feature = "serialize-serde" ) ]
125
91
impl < ' dt , I : Indexed > serde:: Deserialize < ' dt > for Row < I > {
126
92
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)
142
94
}
143
95
}
144
96
@@ -162,8 +114,7 @@ impl Row<ZeroIndexed> {
162
114
}
163
115
}
164
116
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 ) ) ]
167
118
#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
168
119
pub struct Position < I : Indexed > {
169
120
pub row : Row < I > ,
@@ -196,8 +147,7 @@ impl Position<ZeroIndexed> {
196
147
}
197
148
}
198
149
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 ) ) ]
201
151
#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
202
152
pub struct Range < I : Indexed > {
203
153
pub row_start : Row < I > ,
@@ -259,8 +209,7 @@ impl Range<ZeroIndexed> {
259
209
}
260
210
}
261
211
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 ) ) ]
264
213
#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
265
214
pub struct Location < I : Indexed > {
266
215
pub file : PathBuf ,
@@ -295,8 +244,7 @@ impl Location<ZeroIndexed> {
295
244
}
296
245
}
297
246
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 ) ) ]
300
248
#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
301
249
pub struct Span < I : Indexed > {
302
250
pub file : PathBuf ,
@@ -345,17 +293,14 @@ impl Span<ZeroIndexed> {
345
293
}
346
294
}
347
295
348
- #[ cfg( feature = "serialize-serde" ) ]
349
296
pub 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 ) ) ]
354
299
#[ derive( Hash , PartialEq , Eq , Debug , PartialOrd , Ord ) ]
355
300
pub struct ZeroIndexed ;
356
301
impl 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 ) ) ]
359
304
#[ derive( Hash , PartialEq , Eq , Debug , PartialOrd , Ord ) ]
360
305
pub struct OneIndexed ;
361
306
impl Indexed for OneIndexed { }
0 commit comments