@@ -16,7 +16,9 @@ pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Resul
1616 if output. status . success ( ) {
1717 Ok ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
1818 } else {
19- Err ( crate :: Error :: Command ( String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ) . into ( ) )
19+ Err ( crate :: Error :: Command (
20+ String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ,
21+ ) )
2022 }
2123}
2224
@@ -32,7 +34,9 @@ pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Resul
3234 if output. status . success ( ) {
3335 Ok ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
3436 } else {
35- Err ( crate :: Error :: Command ( String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ) . into ( ) )
37+ Err ( crate :: Error :: Command (
38+ String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ,
39+ ) )
3640 }
3741}
3842
@@ -41,7 +45,9 @@ pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Resul
4145pub fn command_path ( command : String ) -> crate :: Result < String > {
4246 match std:: env:: current_exe ( ) ?. parent ( ) {
4347 Some ( exe_dir) => Ok ( format ! ( "{}/{}" , exe_dir. display( ) . to_string( ) , command) ) ,
44- None => Err ( crate :: Error :: Command ( "Could not evaluate executable dir" . to_string ( ) ) . into ( ) ) ,
48+ None => Err ( crate :: Error :: Command (
49+ "Could not evaluate executable dir" . to_string ( ) ,
50+ ) ) ,
4551 }
4652}
4753
@@ -50,7 +56,9 @@ pub fn command_path(command: String) -> crate::Result<String> {
5056pub fn command_path ( command : String ) -> crate :: Result < String > {
5157 match std:: env:: current_exe ( ) ?. parent ( ) {
5258 Some ( exe_dir) => Ok ( format ! ( "{}/{}.exe" , exe_dir. display( ) . to_string( ) , command) ) ,
53- None => Err ( crate :: Error :: Command ( "Could not evaluate executable dir" . to_string ( ) ) . into ( ) ) ,
59+ None => Err ( crate :: Error :: Command (
60+ "Could not evaluate executable dir" . to_string ( ) ,
61+ ) ) ,
5462 }
5563}
5664
@@ -86,14 +94,17 @@ pub fn spawn_relative_command(
8694
8795/// Gets the binary command with the current target triple.
8896pub fn binary_command ( binary_name : String ) -> crate :: Result < String > {
89- Ok ( format ! ( "{}-{}" , binary_name, platform:: target_triple( ) ?) )
97+ Ok ( format ! (
98+ "{}-{}" ,
99+ binary_name,
100+ platform:: target_triple( ) . map_err( |e| crate :: Error :: FailedToDetectPlatform ( e. to_string( ) ) ) ?
101+ ) )
90102}
91103
92104// tests for the commands functions.
93105#[ cfg( test) ]
94106mod test {
95107 use super :: * ;
96- use std:: io;
97108
98109 #[ cfg( not( windows) ) ]
99110 #[ test]
@@ -131,7 +142,7 @@ mod test {
131142 assert ! ( res. is_err( ) ) ;
132143
133144 // destruct the Error to check the ErrorKind and test that it is a Command type.
134- if let Some ( Error :: Command ( e) ) = res. unwrap_err ( ) . downcast_ref :: < Error > ( ) {
145+ if let Error :: Command ( e) = res. unwrap_err ( ) {
135146 // assert that the message in the error matches this string.
136147 assert_eq ! ( * e, "cat: test/: Is a directory\n " . to_string( ) ) ;
137148 }
@@ -163,7 +174,7 @@ mod test {
163174 assert ! ( res. is_err( ) ) ;
164175
165176 // after asserting that the result is an error, check that the error kind is ErrorKind::Io
166- if let Some ( s) = res. unwrap_err ( ) . downcast_ref :: < io :: Error > ( ) {
177+ if let crate :: Error :: Io ( s) = res. unwrap_err ( ) {
167178 // assert that the ErrorKind inside of the ErrorKind Io is ErrorKind::NotFound
168179 assert_eq ! ( s. kind( ) , std:: io:: ErrorKind :: NotFound ) ;
169180 }
0 commit comments