Skip to content

Commit 8593daa

Browse files
authored
Merge pull request #4 from Integralist/integralist/static-not-dynamic-dispatch
refactor: use static dispatch instead of dynamic dispatch
2 parents 4342433 + cb86a69 commit 8593daa

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use std::ffi::OsString;
66
use std::io::Write;
77

88
/// run parses the given itr arguments and triggers the primary program logic.
9-
pub fn run<I, T>(itr: I, output: &mut (dyn Write)) -> Result<()>
9+
pub fn run<I, T, W>(itr: I, output: &mut W) -> Result<()>
1010
where
1111
I: IntoIterator<Item = T>,
1212
T: Into<OsString> + Clone,
13+
W: Write,
1314
{
1415
exec(Args::parse_from(itr), output)
1516
}
@@ -22,9 +23,8 @@ fn run_success() {
2223
.split_whitespace();
2324

2425
let mut output_cursor = Cursor::new(vec![]);
25-
let output_writer: &mut (dyn Write) = &mut output_cursor;
2626

27-
run(itr, output_writer).expect("to run correctly");
27+
run(itr, &mut output_cursor).expect("to run correctly");
2828

2929
let buf = output_cursor.into_inner();
3030
let output = match std::str::from_utf8(&buf) {
@@ -36,7 +36,7 @@ fn run_success() {
3636
}
3737

3838
/// exec makes a HTTP request for the configured URL and constructs a Header for display.
39-
fn exec(args: Args, output: &mut (dyn Write)) -> Result<()> {
39+
fn exec<W: Write>(args: Args, output: &mut W) -> Result<()> {
4040
args.color.init();
4141

4242
let resp = reqwest::blocking::get(&args.url)

src/headers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use reqwest::StatusCode;
77
use std::collections::BTreeMap;
88
use std::io::{BufWriter, Write};
99

10-
pub struct Headers<'a, 'b> {
10+
pub struct Headers<'a, 'b, W: Write> {
1111
filters: Option<String>,
1212
map: &'a HeaderMap,
13-
output: &'b mut (dyn Write),
13+
output: &'b mut W,
1414
}
1515

16-
impl<'a, 'b> Headers<'a, 'b> {
17-
pub fn new(map: &'a HeaderMap, filters: Option<String>, output: &'b mut (dyn Write)) -> Self {
16+
impl<'a, 'b, W: Write> Headers<'a, 'b, W> {
17+
pub fn new(map: &'a HeaderMap, filters: Option<String>, output: &'b mut W) -> Self {
1818
Self {
1919
filters,
2020
map,

0 commit comments

Comments
 (0)