diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/ammonia/examples | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ammonia/examples')
-rw-r--r-- | vendor/ammonia/examples/ammonia-cat.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/ammonia/examples/ammonia-cat.rs b/vendor/ammonia/examples/ammonia-cat.rs new file mode 100644 index 000000000..95a83807d --- /dev/null +++ b/vendor/ammonia/examples/ammonia-cat.rs @@ -0,0 +1,35 @@ +use ammonia::Builder; +use std::env; +use std::fs::File; +use std::io::{self, Read, Write}; +use std::process; + +fn run() -> io::Result<()> { + let input = env::args().nth(1).unwrap_or_else(|| String::from("-")); + let output = env::args().nth(2).unwrap_or_else(|| String::from("-")); + + let mut rdr: Box<dyn Read> = if input == "-" { + Box::new(io::stdin()) + } else { + Box::new(File::open(input)?) + }; + + let mut wrt: Box<dyn Write> = if output == "-" { + Box::new(io::stdout()) + } else { + Box::new(File::create(output)?) + }; + + Builder::new() + .clean_from_reader(&mut rdr)? + .write_to(&mut wrt)?; + Ok(()) +} + +fn main() { + env_logger::init(); + if let Err(ref e) = run() { + println!("error: {}", e); + process::exit(1); + } +} |