Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Delete-a-file/Rust/delete-a-file.rust
Normal file
25
Task/Delete-a-file/Rust/delete-a-file.rust
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::io::{self, Write};
|
||||
use std::fs::{remove_file,remove_dir};
|
||||
use std::path::Path;
|
||||
use std::{process,display};
|
||||
|
||||
const FILE_NAME: &'static str = "output.txt";
|
||||
const DIR_NAME : &'static str = "docs";
|
||||
|
||||
fn main() {
|
||||
delete(".").and(delete("/"))
|
||||
.unwrap_or_else(|e| error_handler(e,1));
|
||||
}
|
||||
|
||||
|
||||
fn delete<P>(root: P) -> io::Result<()>
|
||||
where P: AsRef<Path>
|
||||
{
|
||||
remove_file(root.as_ref().join(FILE_NAME))
|
||||
.and(remove_dir(root.as_ref().join(DIR_NAME)))
|
||||
}
|
||||
|
||||
fn error_handler<E: fmt::Display>(error: E, code: i32) -> ! {
|
||||
let _ = writeln!(&mut io::stderr(), "{:?}", error);
|
||||
process::exit(code)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue