Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/File-size/Rust/file-size.rust
Normal file
18
Task/File-size/Rust/file-size.rust
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use std::{env, fs, process};
|
||||
use std::io::{self, Write};
|
||||
use std::fmt::Display;
|
||||
|
||||
fn main() {
|
||||
let file_name = env::args().nth(1).unwrap_or_else(|| exit_err("No file name supplied", 1));
|
||||
let metadata = fs::metadata(file_name).unwrap_or_else(|e| exit_err(e, 2));
|
||||
|
||||
println!("Size of file.txt is {} bytes", metadata.len());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn exit_err<T: Display>(msg: T, code: i32) -> ! {
|
||||
writeln!(&mut io::stderr(), "Error: {}", msg).expect("Could not write to stdout");
|
||||
process::exit(code)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue