Closed
Description
macro_rules! open_file(
($path_str:expr) => (
::std::io::File::open(&Path::new( $path_str ))
);
($path_str:expr, rw ) => (
::std::io::File::open_mode(&Path::new( $path_str ) , ::std::io::Open,
::std::io::ReadWrite )
);
($path_str:expr, w ) => (
::std::io::File::open_mode(&Path::new( $path_str ) , ::std::io::Open,
::std::io::Write )
);
($path_str:expr, a ) => (
::std::io::File::open_mode(&Path::new( $path_str ) , ::std::io::Append,
::std::io::Write )
);
)
example
fn main(){
let file_path="message.txt";
let mut file = try_or!(
open_file!(file_path ,w ),
"can't open file `{}` : [{}]", file_path,e
);
}
about macro rule try_or! see #12911
Metadata
Metadata
Assignees
Labels
No labels