From ed75b8b766e6009abbedd4c9248e9e2d85d68bc3 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 4 Apr 2022 21:46:48 +0100 Subject: [PATCH] Added default features: buffer-output, ignore-output-errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for reverse's current commit: Half blessing − 半吉 --- Cargo.toml | 7 ++++--- src/main.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b77d45..7bedebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "reverse" -version = "0.2.0" +version = "0.2.1" authors = ["Avril "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["output-lines"] +default = ["output-lines", "buffer-output", "ignore-output-errors"] # Output as lines instead of `["2", "1", "0"]` output-lines = [] @@ -18,7 +18,8 @@ output-quoted = [] # Buffer output to conserve syscalls, useful for very large inputs (can cause higher memory usage, but generally speeds output up considerably) buffer-output = [] -# Do not attempt to handle output errors +# Do not attempt to handle output errors. +# Disable this if you are writing to a faulty device or expect some output operations to stdout to fail. ignore-output-errors = [] [profile.release] diff --git a/src/main.rs b/src/main.rs index e71afe9..928b278 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,11 +46,13 @@ fn collect_input() -> Box + 'static> } } -#[inline(always)] +#[cfg_attr(feature="ignore-output-errors", inline(always))] fn handle_fmt_err(res: std::io::Result) { - #[cfg(not(feature="ignore-output-errors"))] - res.expect("[!] failed to write"); + #[cfg(not(feature="ignore-output-errors"))] + if let Err(e) = res { + eprintln!("[!] failed to write line: {e}"); + } let _ = res; } @@ -82,7 +84,7 @@ fn main() { }); } //#[cfg(feature="buffer-output")] - handle_fmt_err(out.flush()); + handle_fmt_err(out.flush()); //XXX: Do we need to flush when not buffering output? Does it matter since buffering output will be enabled by default and should almost always be enabled? } #[cfg(not(feature="output-lines"))] println!("{:?}", args);