Debian Codegraph @

debian/rust-vendor/memmap2/examples/cat.rs

raw
1 use std::env;
2 use std::fs::File;
3 use std::io::{self, Write};
4
5 use memmap2::Mmap;
6
7 /// Output a file's contents to stdout. The file path must be provided as the first process
8 /// argument.
9 fn main() {
10 let path = env::args()
11 .nth(1)
12 .expect("supply a single path as the program argument");
13
14 let file = File::open(path).expect("failed to open the file");
15
16 let mmap = unsafe { Mmap::map(&file).expect("failed to map the file") };
17
18 io::stdout()
19 .write_all(&mmap[..])
20 .expect("failed to output the file contents");
21 }