Skip to content

Commit

Permalink
Merge pull request #4 from Integralist/integralist/static-not-dynamic…
Browse files Browse the repository at this point in the history
…-dispatch

refactor: use static dispatch instead of dynamic dispatch
  • Loading branch information
Integralist authored Dec 31, 2023
2 parents 4342433 + cb86a69 commit 8593daa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I, T>(itr: I, output: &mut (dyn Write)) -> Result<()>
pub fn run<I, T, W>(itr: I, output: &mut W) -> Result<()>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
W: Write,
{
exec(Args::parse_from(itr), output)
}
Expand All @@ -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) {
Expand All @@ -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<W: Write>(args: Args, output: &mut W) -> Result<()> {
args.color.init();

let resp = reqwest::blocking::get(&args.url)
Expand Down
8 changes: 4 additions & 4 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
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<String>, output: &'b mut (dyn Write)) -> Self {
impl<'a, 'b, W: Write> Headers<'a, 'b, W> {
pub fn new(map: &'a HeaderMap, filters: Option<String>, output: &'b mut W) -> Self {
Self {
filters,
map,
Expand Down

0 comments on commit 8593daa

Please sign in to comment.