1
- use serialize:: Decodable ;
2
1
use std:: collections:: HashMap ;
3
2
use std:: fmt;
4
3
use std:: io:: fs;
5
4
use std:: slice;
6
5
use std:: str;
7
6
use toml;
7
+ use semver;
8
+ use serialize:: { Decodable , Decoder } ;
8
9
9
10
use core:: { SourceId , GitKind } ;
10
11
use core:: manifest:: { LibKind , Lib , Dylib , Profile } ;
@@ -168,14 +169,14 @@ type TomlBenchTarget = TomlTarget;
168
169
* TODO: Make all struct fields private
169
170
*/
170
171
171
- #[ deriving( Encodable , Decodable , PartialEq , Clone , Show ) ]
172
+ #[ deriving( Decodable ) ]
172
173
pub enum TomlDependency {
173
174
SimpleDep ( String ) ,
174
175
DetailedDep ( DetailedTomlDependency )
175
176
}
176
177
177
178
178
- #[ deriving( Encodable , Decodable , PartialEq , Clone , Show ) ]
179
+ #[ deriving( Decodable ) ]
179
180
pub struct DetailedTomlDependency {
180
181
version : Option < String > ,
181
182
path : Option < String > ,
@@ -185,7 +186,7 @@ pub struct DetailedTomlDependency {
185
186
rev : Option < String >
186
187
}
187
188
188
- #[ deriving( Encodable , Decodable , PartialEq , Clone ) ]
189
+ #[ deriving( Decodable ) ]
189
190
pub struct TomlManifest {
190
191
package : Option < Box < TomlProject > > ,
191
192
project : Option < Box < TomlProject > > ,
@@ -198,7 +199,7 @@ pub struct TomlManifest {
198
199
dev_dependencies : Option < HashMap < String , TomlDependency > > ,
199
200
}
200
201
201
- #[ deriving( Encodable , Decodable , PartialEq , Clone ) ]
202
+ #[ deriving( Decodable ) ]
202
203
pub enum ManyOrOne < T > {
203
204
Many ( Vec < T > ) ,
204
205
One ( T ) ,
@@ -213,25 +214,40 @@ impl<T> ManyOrOne<T> {
213
214
}
214
215
}
215
216
216
- #[ deriving( Decodable , Encodable , PartialEq , Clone , Show ) ]
217
+ #[ deriving( Decodable ) ]
217
218
pub struct TomlProject {
218
- pub name : String ,
219
- // FIXME #54: should be a Version to be able to be Decodable'd directly.
220
- pub version : String ,
219
+ name : String ,
220
+ version : TomlVersion ,
221
221
pub authors : Vec < String > ,
222
222
build : Option < TomlBuildCommandsList > ,
223
223
exclude : Option < Vec < String > > ,
224
224
}
225
225
226
- #[ deriving( Encodable , Decodable , PartialEq , Clone , Show ) ]
226
+ #[ deriving( Decodable ) ]
227
227
pub enum TomlBuildCommandsList {
228
228
SingleBuildCommand ( String ) ,
229
229
MultipleBuildCommands ( Vec < String > )
230
230
}
231
231
232
+ pub struct TomlVersion {
233
+ version : semver:: Version ,
234
+ }
235
+
236
+ impl < E , D : Decoder < E > > Decodable < D , E > for TomlVersion {
237
+ fn decode ( d : & mut D ) -> Result < TomlVersion , E > {
238
+ let s = raw_try ! ( d. read_str( ) ) ;
239
+ match semver:: parse ( s. as_slice ( ) ) {
240
+ Some ( s) => Ok ( TomlVersion { version : s } ) ,
241
+ None => Err ( d. error ( format ! ( "cannot parse '{}' as a semver" ,
242
+ s) . as_slice ( ) ) ) ,
243
+ }
244
+ }
245
+ }
246
+
232
247
impl TomlProject {
233
248
pub fn to_package_id ( & self , source_id : & SourceId ) -> CargoResult < PackageId > {
234
- PackageId :: new ( self . name . as_slice ( ) , self . version . as_slice ( ) , source_id)
249
+ PackageId :: new ( self . name . as_slice ( ) , self . version . version . clone ( ) ,
250
+ source_id)
235
251
}
236
252
}
237
253
@@ -395,7 +411,7 @@ impl TomlManifest {
395
411
& metadata) ;
396
412
397
413
if targets. is_empty ( ) {
398
- debug ! ( "manifest has no build targets; project={}" , self . project ) ;
414
+ debug ! ( "manifest has no build targets" ) ;
399
415
}
400
416
401
417
let mut deps = Vec :: new ( ) ;
@@ -490,7 +506,7 @@ fn process_dependencies<'a>(cx: &mut Context<'a>, dev: bool,
490
506
Ok ( ( ) )
491
507
}
492
508
493
- #[ deriving( Decodable , Encodable , PartialEq , Clone , Show ) ]
509
+ #[ deriving( Decodable , Show , Clone ) ]
494
510
struct TomlTarget {
495
511
name : String ,
496
512
crate_type : Option < Vec < String > > ,
@@ -503,7 +519,7 @@ struct TomlTarget {
503
519
harness : Option < bool > ,
504
520
}
505
521
506
- #[ deriving( Decodable , Encodable , PartialEq , Clone ) ]
522
+ #[ deriving( Decodable , Clone ) ]
507
523
enum TomlPath {
508
524
TomlString ( String ) ,
509
525
TomlPath ( Path ) ,
0 commit comments