File tree Expand file tree Collapse file tree 7 files changed +15
-14
lines changed
tmc-langs-core/src/tmc_core Expand file tree Collapse file tree 7 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -752,8 +752,8 @@ fn into_usize(arg: &str) -> Result<usize> {
752752
753753fn into_locale ( arg : & str ) -> Result < Language > {
754754 Language :: from_locale ( arg)
755- . or ( Language :: from_639_1 ( arg) )
756- . or ( Language :: from_639_3 ( arg) )
755+ . or_else ( || Language :: from_639_1 ( arg) )
756+ . or_else ( || Language :: from_639_3 ( arg) )
757757 . with_context ( || format ! ( "Invalid locale: {}" , arg) )
758758}
759759
Original file line number Diff line number Diff line change @@ -31,14 +31,14 @@ trait CoreExt {
3131impl CoreExt for ReqwestResponse {
3232 #[ cfg( not( test) ) ]
3333 fn json_res < T : DeserializeOwned > ( self ) -> Result < T > {
34- let res: Response < T > = self . json ( ) . map_err ( |e| CoreError :: HttpJsonResponse ( e ) ) ?;
34+ let res: Response < T > = self . json ( ) . map_err ( CoreError :: HttpJsonResponse ) ?;
3535 res. into_result ( )
3636 }
3737
3838 // logs received JSON for easier debugging in tests
3939 #[ cfg( test) ]
4040 fn json_res < T : DeserializeOwned > ( self ) -> Result < T > {
41- let res: Value = self . json ( ) . map_err ( |e| CoreError :: HttpJsonResponse ( e ) ) ?;
41+ let res: Value = self . json ( ) . map_err ( CoreError :: HttpJsonResponse ) ?;
4242 log:: debug!( "JSON {}" , res) ;
4343 let res: Response < T > = serde_json:: from_value ( res) . unwrap ( ) ;
4444 res. into_result ( )
@@ -49,7 +49,7 @@ impl CoreExt for ReqwestResponse {
4949 if status. is_success ( ) {
5050 Ok ( self )
5151 } else {
52- let text = self . text ( ) . unwrap_or ( String :: new ( ) ) ;
52+ let text = self . text ( ) . unwrap_or_default ( ) ;
5353 Err ( CoreError :: HttpStatus ( url, status, text) )
5454 }
5555 }
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ use zip::ZipArchive;
2424
2525const TMC_CSHARP_RUNNER : & [ u8 ] = include_bytes ! ( "../tmc-csharp-runner-1.0.1.zip" ) ;
2626
27+ #[ derive( Default ) ]
2728pub struct CSharpPlugin { }
2829
2930impl CSharpPlugin {
@@ -35,8 +36,7 @@ impl CSharpPlugin {
3536 fn extract_runner ( target : & Path ) -> Result < ( ) , CSharpError > {
3637 log:: debug!( "extracting C# runner to {}" , target. display( ) ) ;
3738
38- let mut zip =
39- ZipArchive :: new ( Cursor :: new ( TMC_CSHARP_RUNNER ) ) . map_err ( |e| CSharpError :: Zip ( e) ) ?;
39+ let mut zip = ZipArchive :: new ( Cursor :: new ( TMC_CSHARP_RUNNER ) ) . map_err ( CSharpError :: Zip ) ?;
4040 for i in 0 ..zip. len ( ) {
4141 let file = zip. by_index ( i) . unwrap ( ) ;
4242 if file. is_file ( ) {
@@ -85,7 +85,7 @@ impl CSharpPlugin {
8585 log:: debug!( "found boostrap dll at {}" , bootstrap. display( ) ) ;
8686 Ok ( bootstrap)
8787 } else {
88- Err ( CSharpError :: MissingBootstrapDll ( bootstrap) . into ( ) )
88+ Err ( CSharpError :: MissingBootstrapDll ( bootstrap) )
8989 }
9090 }
9191 }
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ impl CommandWithTimeout<'_> {
3434 . map_err ( |e| TmcError :: CommandSpawn ( name, e) ) ?;
3535 let timer = Instant :: now ( ) ;
3636 loop {
37- match child. try_wait ( ) . map_err ( |e| TmcError :: Process ( e ) ) ? {
37+ match child. try_wait ( ) . map_err ( TmcError :: Process ) ? {
3838 Some ( _exit_status) => {
3939 // done, get output
4040 return child
@@ -44,7 +44,7 @@ impl CommandWithTimeout<'_> {
4444 None => {
4545 // still running, check timeout
4646 if timer. elapsed ( ) > timeout {
47- child. kill ( ) . map_err ( |e| TmcError :: Process ( e ) ) ?;
47+ child. kill ( ) . map_err ( TmcError :: Process ) ?;
4848 return Err ( TmcError :: TestTimeout ( timer. elapsed ( ) ) ) ;
4949 }
5050
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ impl NoTestsPlugin {
2323 . get_tmc_project_yml ( )
2424 . ok ( )
2525 . and_then ( |c| c. no_tests . map ( |n| n. points ) )
26- . unwrap_or ( vec ! [ ] )
26+ . unwrap_or_default ( )
2727 }
2828}
2929
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use std::path::Path;
1616use std:: process:: Command ;
1717use std:: time:: Duration ;
1818
19+ #[ derive( Default ) ]
1920pub struct RPlugin { }
2021
2122impl RPlugin {
Original file line number Diff line number Diff line change @@ -28,13 +28,13 @@ pub fn create_tar_from_project(
2828 let project_name = Path :: new (
2929 project_dir
3030 . file_name ( )
31- . ok_or ( TmcError :: NoFileName ( project_dir. to_path_buf ( ) ) ) ?,
31+ . ok_or_else ( || TmcError :: NoFileName ( project_dir. to_path_buf ( ) ) ) ?,
3232 ) ;
3333 let root = project_dir. parent ( ) . unwrap_or_else ( || Path :: new ( "" ) ) ;
3434 add_dir_to_project ( & mut tar, & project_dir, project_dir, & project_name) ?;
3535 add_dir_to_project ( & mut tar, & tmc_langs, root, & project_name) ?;
3636 add_dir_to_project ( & mut tar, & tmcrun, root, & project_name) ?;
37- tar. finish ( ) . map_err ( |e| TmcError :: TarFinish ( e ) ) ?;
37+ tar. finish ( ) . map_err ( TmcError :: TarFinish ) ?;
3838 Ok ( ( ) )
3939}
4040
@@ -51,7 +51,7 @@ fn add_dir_to_project<W: Write>(
5151 let path_in_tar: PathBuf = project_name. join ( path_in_project) ;
5252 log:: trace!( "appending {:?} as {:?}" , entry. path( ) , path_in_tar) ;
5353 tar. append_path_with_name ( entry. path ( ) , path_in_tar)
54- . map_err ( |e| TmcError :: TarAppend ( e ) ) ?;
54+ . map_err ( TmcError :: TarAppend ) ?;
5555 }
5656 }
5757 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments