Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use static dispatch instead of dynamic dispatch #4

Merged
merged 1 commit into from
Dec 31, 2023

Conversation

Integralist
Copy link
Owner

@Integralist Integralist commented Dec 31, 2023

I'm not sure why I thought I needed dynamic dispatch for this particular example.

@Integralist Integralist added the refactor clean-up of code label Dec 31, 2023
@@ -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;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! I don't have to use this ugly conversion any more 🎉

@@ -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> {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly I didn't HAVE to assign a trait bound here.

I'm presuming the compiler was able to figure that out from the below impl block which does use a trait bound (at the compiler's request).

That said, I decided to be explicit about the trait bound here.

@Integralist Integralist merged commit 8593daa into main Dec 31, 2023
6 checks passed
@Integralist Integralist deleted the integralist/static-not-dynamic-dispatch branch December 31, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor clean-up of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant