From cb86a69c5cab8e923353f4abba79c9dc0e8c94e4 Mon Sep 17 00:00:00 2001 From: Integralist Date: Sun, 31 Dec 2023 20:53:18 +0000 Subject: [PATCH] refactor: use static dispatch instead of dynamic dispatch --- src/app.rs | 8 ++++---- src/headers.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app.rs b/src/app.rs index dc145eb..81ada86 100644 --- a/src/app.rs +++ b/src/app.rs @@ -6,10 +6,11 @@ use std::ffi::OsString; use std::io::Write; /// run parses the given itr arguments and triggers the primary program logic. -pub fn run(itr: I, output: &mut (dyn Write)) -> Result<()> +pub fn run(itr: I, output: &mut W) -> Result<()> where I: IntoIterator, T: Into + Clone, + W: Write, { exec(Args::parse_from(itr), output) } @@ -22,9 +23,8 @@ fn run_success() { .split_whitespace(); let mut output_cursor = Cursor::new(vec![]); - let output_writer: &mut (dyn Write) = &mut output_cursor; - run(itr, output_writer).expect("to run correctly"); + run(itr, &mut output_cursor).expect("to run correctly"); let buf = output_cursor.into_inner(); let output = match std::str::from_utf8(&buf) { @@ -36,7 +36,7 @@ fn run_success() { } /// exec makes a HTTP request for the configured URL and constructs a Header for display. -fn exec(args: Args, output: &mut (dyn Write)) -> Result<()> { +fn exec(args: Args, output: &mut W) -> Result<()> { args.color.init(); let resp = reqwest::blocking::get(&args.url) diff --git a/src/headers.rs b/src/headers.rs index cdc6d4c..eff0229 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -7,14 +7,14 @@ use reqwest::StatusCode; use std::collections::BTreeMap; use std::io::{BufWriter, Write}; -pub struct Headers<'a, 'b> { +pub struct Headers<'a, 'b, W: Write> { filters: Option, map: &'a HeaderMap, - output: &'b mut (dyn Write), + output: &'b mut W, } -impl<'a, 'b> Headers<'a, 'b> { - pub fn new(map: &'a HeaderMap, filters: Option, output: &'b mut (dyn Write)) -> Self { +impl<'a, 'b, W: Write> Headers<'a, 'b, W> { + pub fn new(map: &'a HeaderMap, filters: Option, output: &'b mut W) -> Self { Self { filters, map,