1
1
use crate :: cmd:: Command ;
2
- use crate :: { Crate , Toolchain , Workspace , build :: CratePatch } ;
2
+ use crate :: { build :: CratePatch , Crate , Toolchain , Workspace } ;
3
3
use failure:: { Error , Fail , ResultExt } ;
4
4
use log:: info;
5
5
use std:: path:: Path ;
@@ -14,7 +14,7 @@ pub(crate) struct Prepare<'a> {
14
14
krate : & ' a Crate ,
15
15
source_dir : & ' a Path ,
16
16
lockfile_captured : bool ,
17
- patches : Vec < CratePatch >
17
+ patches : Vec < CratePatch > ,
18
18
}
19
19
20
20
impl < ' a > Prepare < ' a > {
@@ -23,7 +23,7 @@ impl<'a> Prepare<'a> {
23
23
toolchain : & ' a Toolchain ,
24
24
krate : & ' a Crate ,
25
25
source_dir : & ' a Path ,
26
- patches : Vec < CratePatch >
26
+ patches : Vec < CratePatch > ,
27
27
) -> Self {
28
28
Self {
29
29
workspace,
@@ -150,15 +150,24 @@ pub struct TomlTweaker<'a> {
150
150
}
151
151
152
152
impl < ' a > TomlTweaker < ' a > {
153
- pub fn new ( krate : & ' a Crate , cargo_toml : & ' a Path , patches : & [ CratePatch ] ) -> Result < Self , Error > {
153
+ pub fn new (
154
+ krate : & ' a Crate ,
155
+ cargo_toml : & ' a Path ,
156
+ patches : & [ CratePatch ] ,
157
+ ) -> Result < Self , Error > {
154
158
let toml_content = :: std:: fs:: read_to_string ( cargo_toml)
155
159
. with_context ( |_| PrepareError :: MissingCargoToml ) ?;
156
160
let table: Table =
157
161
toml:: from_str ( & toml_content) . with_context ( |_| PrepareError :: InvalidCargoTomlSyntax ) ?;
158
162
159
163
let dir = cargo_toml. parent ( ) ;
160
164
161
- Ok ( TomlTweaker { krate, table, dir, patches : patches. to_vec ( ) } )
165
+ Ok ( TomlTweaker {
166
+ krate,
167
+ table,
168
+ dir,
169
+ patches : patches. to_vec ( ) ,
170
+ } )
162
171
}
163
172
164
173
#[ cfg( test) ]
@@ -287,16 +296,20 @@ impl<'a> TomlTweaker<'a> {
287
296
let patch_table = match patch_table {
288
297
Some ( ref mut pt) => pt,
289
298
None => {
290
- self . table . insert ( "patch" . to_string ( ) , Value :: Table ( Table :: new ( ) ) ) ;
299
+ self . table
300
+ . insert ( "patch" . to_string ( ) , Value :: Table ( Table :: new ( ) ) ) ;
291
301
self . table . get_mut ( "patch" ) . unwrap ( )
292
- } ,
302
+ }
293
303
} ;
294
304
295
305
let mut cratesio_table = patch_table. get_mut ( "crates-io" ) ;
296
306
let cratesio_table = match cratesio_table {
297
307
Some ( ref mut cio) => cio,
298
308
None => {
299
- patch_table. as_table_mut ( ) . unwrap ( ) . insert ( "crates-io" . to_string ( ) , Value :: Table ( Table :: new ( ) ) ) ;
309
+ patch_table
310
+ . as_table_mut ( )
311
+ . unwrap ( )
312
+ . insert ( "crates-io" . to_string ( ) , Value :: Table ( Table :: new ( ) ) ) ;
300
313
patch_table. get_mut ( "crates-io" ) . unwrap ( )
301
314
}
302
315
} ;
@@ -305,7 +318,10 @@ impl<'a> TomlTweaker<'a> {
305
318
let mut table = Table :: new ( ) ;
306
319
table. insert ( "git" . into ( ) , Value :: String ( patch. uri ) ) ;
307
320
table. insert ( "branch" . into ( ) , Value :: String ( patch. branch ) ) ;
308
- cratesio_table. as_table_mut ( ) . unwrap ( ) . insert ( patch. name , Value :: Table ( table) ) ;
321
+ cratesio_table
322
+ . as_table_mut ( )
323
+ . unwrap ( )
324
+ . insert ( patch. name , Value :: Table ( table) ) ;
309
325
}
310
326
}
311
327
}
@@ -365,8 +381,8 @@ pub enum PrepareError {
365
381
#[ cfg( test) ]
366
382
mod tests {
367
383
use super :: TomlTweaker ;
368
- use crate :: crates:: Crate ;
369
384
use crate :: build:: CratePatch ;
385
+ use crate :: crates:: Crate ;
370
386
use toml:: { self , Value } ;
371
387
372
388
#[ test]
@@ -392,7 +408,8 @@ mod tests {
392
408
393
409
let krate = Crate :: local ( "/dev/null" . as_ref ( ) ) ;
394
410
let patches: Vec < CratePatch > = Vec :: new ( ) ;
395
- let mut tweaker = TomlTweaker :: new_with_table ( & krate, toml. as_table ( ) . unwrap ( ) . clone ( ) , & patches) ;
411
+ let mut tweaker =
412
+ TomlTweaker :: new_with_table ( & krate, toml. as_table ( ) . unwrap ( ) . clone ( ) , & patches) ;
396
413
tweaker. tweak ( ) ;
397
414
398
415
assert_eq ! ( Value :: Table ( tweaker. table) , result) ;
@@ -442,7 +459,8 @@ mod tests {
442
459
443
460
let krate = Crate :: local ( "/dev/null" . as_ref ( ) ) ;
444
461
let patches: Vec < CratePatch > = Vec :: new ( ) ;
445
- let mut tweaker = TomlTweaker :: new_with_table ( & krate, toml. as_table ( ) . unwrap ( ) . clone ( ) , & patches) ;
462
+ let mut tweaker =
463
+ TomlTweaker :: new_with_table ( & krate, toml. as_table ( ) . unwrap ( ) . clone ( ) , & patches) ;
446
464
tweaker. tweak ( ) ;
447
465
448
466
assert_eq ! ( Value :: Table ( tweaker. table) , result) ;
@@ -488,14 +506,13 @@ mod tests {
488
506
} ;
489
507
490
508
let krate = Crate :: local ( "/dev/null" . as_ref ( ) ) ;
491
- let patches = vec ! [
492
- CratePatch {
493
- name: "quux" . into( ) ,
494
- uri: "https://git.example.com/quux" . into( ) ,
495
- branch: "dev" . into( ) ,
496
- }
497
- ] ;
498
- let mut tweaker = TomlTweaker :: new_with_table ( & krate, toml. as_table ( ) . unwrap ( ) . clone ( ) , & patches) ;
509
+ let patches = vec ! [ CratePatch {
510
+ name: "quux" . into( ) ,
511
+ uri: "https://git.example.com/quux" . into( ) ,
512
+ branch: "dev" . into( ) ,
513
+ } ] ;
514
+ let mut tweaker =
515
+ TomlTweaker :: new_with_table ( & krate, toml. as_table ( ) . unwrap ( ) . clone ( ) , & patches) ;
499
516
tweaker. tweak ( ) ;
500
517
501
518
assert_eq ! ( Value :: Table ( tweaker. table) , result) ;
0 commit comments