@@ -63,10 +63,8 @@ pub struct Component {
63
63
64
64
impl Manifest {
65
65
pub fn parse ( data : & str ) -> Result < Self > {
66
- let mut parser = toml:: Parser :: new ( data) ;
67
- let value = try!( parser. parse ( ) . ok_or_else ( move || ErrorKind :: Parsing ( parser. errors ) ) ) ;
68
-
69
- let manifest = try!( Self :: from_toml ( value, "" ) ) ;
66
+ let value = toml:: from_str ( data) . map_err ( ErrorKind :: Parsing ) ?;
67
+ let manifest = Self :: from_toml ( value, "" ) ?;
70
68
try!( manifest. validate ( ) ) ;
71
69
72
70
Ok ( manifest)
@@ -75,7 +73,7 @@ impl Manifest {
75
73
toml:: Value :: Table ( self . to_toml ( ) ) . to_string ( )
76
74
}
77
75
78
- pub fn from_toml ( mut table : toml:: Table , path : & str ) -> Result < Self > {
76
+ pub fn from_toml ( mut table : toml:: value :: Table , path : & str ) -> Result < Self > {
79
77
let version = try!( get_string ( & mut table, "manifest-version" , path) ) ;
80
78
if !SUPPORTED_MANIFEST_VERSIONS . contains ( & & * version) {
81
79
return Err ( ErrorKind :: UnsupportedVersion ( version) . into ( ) ) ;
@@ -87,8 +85,8 @@ impl Manifest {
87
85
renames : try!( Self :: table_to_renames ( table, path) ) ,
88
86
} )
89
87
}
90
- pub fn to_toml ( self ) -> toml:: Table {
91
- let mut result = toml:: Table :: new ( ) ;
88
+ pub fn to_toml ( self ) -> toml:: value :: Table {
89
+ let mut result = toml:: value :: Table :: new ( ) ;
92
90
93
91
result. insert ( "date" . to_owned ( ) , toml:: Value :: String ( self . date ) ) ;
94
92
result. insert ( "manifest-version" . to_owned ( ) ,
@@ -103,7 +101,7 @@ impl Manifest {
103
101
result
104
102
}
105
103
106
- fn table_to_packages ( table : & mut toml:: Table , path : & str ) -> Result < HashMap < String , Package > > {
104
+ fn table_to_packages ( table : & mut toml:: value :: Table , path : & str ) -> Result < HashMap < String , Package > > {
107
105
let mut result = HashMap :: new ( ) ;
108
106
let pkg_table = try!( get_table ( table, "pkg" , path) ) ;
109
107
@@ -115,15 +113,15 @@ impl Manifest {
115
113
116
114
Ok ( result)
117
115
}
118
- fn packages_to_table ( packages : HashMap < String , Package > ) -> toml:: Table {
119
- let mut result = toml:: Table :: new ( ) ;
116
+ fn packages_to_table ( packages : HashMap < String , Package > ) -> toml:: value :: Table {
117
+ let mut result = toml:: value :: Table :: new ( ) ;
120
118
for ( k, v) in packages {
121
119
result. insert ( k, toml:: Value :: Table ( v. to_toml ( ) ) ) ;
122
120
}
123
121
result
124
122
}
125
123
126
- fn table_to_renames ( mut table : toml:: Table , path : & str ) -> Result < HashMap < String , String > > {
124
+ fn table_to_renames ( mut table : toml:: value :: Table , path : & str ) -> Result < HashMap < String , String > > {
127
125
let mut result = HashMap :: new ( ) ;
128
126
let rename_table = try!( get_table ( & mut table, "rename" , path) ) ;
129
127
@@ -135,10 +133,10 @@ impl Manifest {
135
133
136
134
Ok ( result)
137
135
}
138
- fn renames_to_table ( renames : HashMap < String , String > ) -> toml:: Table {
139
- let mut result = toml:: Table :: new ( ) ;
136
+ fn renames_to_table ( renames : HashMap < String , String > ) -> toml:: value :: Table {
137
+ let mut result = toml:: value :: Table :: new ( ) ;
140
138
for ( from, to) in renames {
141
- let mut table = toml:: Table :: new ( ) ;
139
+ let mut table = toml:: value :: Table :: new ( ) ;
142
140
table. insert ( "to" . to_owned ( ) , toml:: Value :: String ( to) ) ;
143
141
result. insert ( from, toml:: Value :: Table ( table) ) ;
144
142
}
@@ -190,14 +188,14 @@ impl Manifest {
190
188
}
191
189
192
190
impl Package {
193
- pub fn from_toml ( mut table : toml:: Table , path : & str ) -> Result < Self > {
191
+ pub fn from_toml ( mut table : toml:: value :: Table , path : & str ) -> Result < Self > {
194
192
Ok ( Package {
195
193
version : try!( get_string ( & mut table, "version" , path) ) ,
196
194
targets : try!( Self :: toml_to_targets ( table, path) ) ,
197
195
} )
198
196
}
199
- pub fn to_toml ( self ) -> toml:: Table {
200
- let mut result = toml:: Table :: new ( ) ;
197
+ pub fn to_toml ( self ) -> toml:: value :: Table {
198
+ let mut result = toml:: value :: Table :: new ( ) ;
201
199
202
200
result. insert ( "version" . to_owned ( ) , toml:: Value :: String ( self . version ) ) ;
203
201
@@ -207,7 +205,7 @@ impl Package {
207
205
result
208
206
}
209
207
210
- fn toml_to_targets ( mut table : toml:: Table , path : & str ) -> Result < PackageTargets > {
208
+ fn toml_to_targets ( mut table : toml:: value :: Table , path : & str ) -> Result < PackageTargets > {
211
209
let mut target_table = try!( get_table ( & mut table, "target" , path) ) ;
212
210
213
211
if let Some ( toml:: Value :: Table ( t) ) = target_table. remove ( "*" ) {
@@ -222,8 +220,8 @@ impl Package {
222
220
Ok ( PackageTargets :: Targeted ( result) )
223
221
}
224
222
}
225
- fn targets_to_toml ( targets : PackageTargets ) -> toml:: Table {
226
- let mut result = toml:: Table :: new ( ) ;
223
+ fn targets_to_toml ( targets : PackageTargets ) -> toml:: value :: Table {
224
+ let mut result = toml:: value :: Table :: new ( ) ;
227
225
match targets {
228
226
PackageTargets :: Wildcard ( tpkg) => {
229
227
result. insert ( "*" . to_owned ( ) , toml:: Value :: Table ( tpkg. to_toml ( ) ) ) ;
@@ -268,7 +266,7 @@ impl PackageTargets {
268
266
}
269
267
270
268
impl TargetedPackage {
271
- pub fn from_toml ( mut table : toml:: Table , path : & str ) -> Result < Self > {
269
+ pub fn from_toml ( mut table : toml:: value :: Table , path : & str ) -> Result < Self > {
272
270
let components = try!( get_array ( & mut table, "components" , path) ) ;
273
271
let extensions = try!( get_array ( & mut table, "extensions" , path) ) ;
274
272
@@ -293,10 +291,10 @@ impl TargetedPackage {
293
291
} )
294
292
}
295
293
}
296
- pub fn to_toml ( self ) -> toml:: Table {
294
+ pub fn to_toml ( self ) -> toml:: value :: Table {
297
295
let extensions = Self :: components_to_toml ( self . extensions ) ;
298
296
let components = Self :: components_to_toml ( self . components ) ;
299
- let mut result = toml:: Table :: new ( ) ;
297
+ let mut result = toml:: value :: Table :: new ( ) ;
300
298
if !extensions. is_empty ( ) {
301
299
result. insert ( "extensions" . to_owned ( ) , toml:: Value :: Array ( extensions) ) ;
302
300
}
@@ -321,7 +319,7 @@ impl TargetedPackage {
321
319
self . bins . is_some ( )
322
320
}
323
321
324
- fn toml_to_components ( arr : toml:: Array , path : & str ) -> Result < Vec < Component > > {
322
+ fn toml_to_components ( arr : toml:: value :: Array , path : & str ) -> Result < Vec < Component > > {
325
323
let mut result = Vec :: new ( ) ;
326
324
327
325
for ( i, v) in arr. into_iter ( ) . enumerate ( ) {
@@ -333,8 +331,8 @@ impl TargetedPackage {
333
331
334
332
Ok ( result)
335
333
}
336
- fn components_to_toml ( components : Vec < Component > ) -> toml:: Array {
337
- let mut result = toml:: Array :: new ( ) ;
334
+ fn components_to_toml ( components : Vec < Component > ) -> toml:: value :: Array {
335
+ let mut result = toml:: value :: Array :: new ( ) ;
338
336
for v in components {
339
337
result. push ( toml:: Value :: Table ( v. to_toml ( ) ) ) ;
340
338
}
@@ -343,7 +341,7 @@ impl TargetedPackage {
343
341
}
344
342
345
343
impl Component {
346
- pub fn from_toml ( mut table : toml:: Table , path : & str ) -> Result < Self > {
344
+ pub fn from_toml ( mut table : toml:: value :: Table , path : & str ) -> Result < Self > {
347
345
Ok ( Component {
348
346
pkg : try!( get_string ( & mut table, "pkg" , path) ) ,
349
347
target : try!( get_string ( & mut table, "target" , path) . map ( |s| {
@@ -355,8 +353,8 @@ impl Component {
355
353
} ) ) ,
356
354
} )
357
355
}
358
- pub fn to_toml ( self ) -> toml:: Table {
359
- let mut result = toml:: Table :: new ( ) ;
356
+ pub fn to_toml ( self ) -> toml:: value :: Table {
357
+ let mut result = toml:: value :: Table :: new ( ) ;
360
358
result. insert ( "target" . to_owned ( ) , toml:: Value :: String (
361
359
self . target . map ( |t| t. to_string ( ) ) . unwrap_or_else ( ||"*" . to_owned ( ) )
362
360
) ) ;
0 commit comments