diff --git a/src/cli/apply.rs b/src/cli/apply.rs index c79204b..94100ff 100644 --- a/src/cli/apply.rs +++ b/src/cli/apply.rs @@ -58,9 +58,9 @@ pub fn apply(args: ApplyArgs) -> CliResult { // Bind for later use. let confirmed_count = result.confirmed.len(); - let mut out: Box = match &args.output { - Some(path) => Box::new(File::create(path)?), - None => Box::new(stdout()), + let mut out: &mut dyn Write = match &args.output { + Some(path) => &mut File::create(path)?, + None => &mut stdout(), }; let msg_f = || { let out_description = args diff --git a/src/cli/cleanup_allowlist.rs b/src/cli/cleanup_allowlist.rs index dc52a24..1b2abee 100644 --- a/src/cli/cleanup_allowlist.rs +++ b/src/cli/cleanup_allowlist.rs @@ -35,9 +35,9 @@ pub fn cleanup_allowlist(args: CleanupAllowlistArgs) -> CliResult { .for_each(|rule| { rule.remove("allowlist"); }); - let mut out: Box = match args.output { - Some(path) => Box::new(File::create(path)?), - None => Box::new(stdout()), + let mut out: &mut dyn Write = match args.output { + Some(path) => &mut File::create(path)?, + None => &mut stdout(), }; write!(&mut out, "{doc}")?; SUCCESS diff --git a/src/cli/cleanup_rule.rs b/src/cli/cleanup_rule.rs index db40230..5c6c93f 100644 --- a/src/cli/cleanup_rule.rs +++ b/src/cli/cleanup_rule.rs @@ -73,9 +73,9 @@ pub fn cleanup_rule(args: CleanupRuleArgs) -> CliResult { !contain }); - let mut out: Box = match args.output { - Some(path) => Box::new(File::create(path)?), - None => Box::new(stdout()), + let mut out: &mut dyn Write = match args.output { + Some(path) => &mut File::create(path)?, + None => &mut stdout(), }; write!(&mut out, "{doc}")?; SUCCESS diff --git a/src/cli/diff.rs b/src/cli/diff.rs index 3cc53f6..d91cb47 100644 --- a/src/cli/diff.rs +++ b/src/cli/diff.rs @@ -62,9 +62,9 @@ pub fn diff(args: DiffArgs) -> CliResult { .with_context(|| format!("Failed to parse JSON: {}", after_path.display()))?; let diffs = compute_diff(befores, afters); - let mut out: Box = match args.output.clone() { - Some(path) => Box::new(File::create(path)?), - None => Box::new(stdout()), + let mut out: &mut dyn Write = match args.output.clone() { + Some(path) => &mut File::create(path)?, + None => &mut stdout(), }; match args.format { diff --git a/src/cli/extract_allowlist.rs b/src/cli/extract_allowlist.rs index c170cdf..f2ddac7 100644 --- a/src/cli/extract_allowlist.rs +++ b/src/cli/extract_allowlist.rs @@ -1,6 +1,6 @@ use std::{ fs::{self, read_to_string}, - io, + io::{self, Write}, path::PathBuf, }; @@ -51,9 +51,9 @@ pub fn extract_allowlist(args: ExtractAllowlistArgs) -> CliResult { .collect::>(); let config = ConfigRoot::new(allowlists); - let mut out: Box = match args.output { - Some(path) => Box::new(fs::File::create(path)?), - None => Box::new(io::stdout()), + let mut out: &mut dyn Write = match args.output { + Some(path) => &mut fs::File::create(path)?, + None => &mut io::stdout(), }; write!(&mut out, "{}", toml::to_string(&config)?)?; SUCCESS diff --git a/src/cli/format.rs b/src/cli/format.rs index 0965171..ac7d678 100644 --- a/src/cli/format.rs +++ b/src/cli/format.rs @@ -22,9 +22,9 @@ pub struct FormatArgs { pub fn format(args: FormatArgs) -> CliResult { let contents = read_to_string(args.source)?; let config: ConfigRoot = toml::from_str(&contents)?; - let mut out: Box = match args.output { - Some(path) => Box::new(File::create(path)?), - None => Box::new(stdout()), + let mut out: &mut dyn Write = match args.output { + Some(path) => &mut File::create(path)?, + None => &mut stdout(), }; write!(&mut out, "{}", toml::to_string(&config)?)?; writeln!(out)?; diff --git a/src/cli/review.rs b/src/cli/review.rs index 86167e6..350e786 100644 --- a/src/cli/review.rs +++ b/src/cli/review.rs @@ -91,9 +91,9 @@ pub fn review(args: ReviewArgs) -> CliResult { .map(|report| filter.apply_report(report)) .collect::>(); - let mut out: Box = match args.output.as_ref() { - Some(path) => Box::new(File::create(path)?), - None => Box::new(stdout()), + let mut out: &mut dyn Write = match args.output.as_ref() { + Some(path) => &mut File::create(path)?, + None => &mut stdout(), }; match args.mode { Mode::Summary => print_summary(&results, &filter, &mut out)?,