]> git.proxmox.com Git - rustc.git/blob - vendor/memmap2/examples/cat.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / vendor / memmap2 / examples / cat.rs
1 extern crate memmap2;
2
3 use std::env;
4 use std::fs::File;
5 use std::io::{self, Write};
6
7 use memmap2::Mmap;
8
9 /// Output a file's contents to stdout. The file path must be provided as the first process
10 /// argument.
11 fn main() {
12 let path = env::args()
13 .nth(1)
14 .expect("supply a single path as the program argument");
15
16 let file = File::open(path).expect("failed to open the file");
17
18 let mmap = unsafe { Mmap::map(&file).expect("failed to map the file") };
19
20 io::stdout()
21 .write_all(&mmap[..])
22 .expect("failed to output the file contents");
23 }