Skip to content

tee: dedup code by static dispatch macro#12076

Closed
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:tee-dispatch
Closed

tee: dedup code by static dispatch macro#12076
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:tee-dispatch

Conversation

@oech3
Copy link
Copy Markdown
Contributor

@oech3 oech3 commented Apr 29, 2026

No description provided.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/pipe-f is now passing!

@oech3 oech3 marked this pull request as ready for review April 29, 2026 03:39
@xtqqczze
Copy link
Copy Markdown
Contributor

This may be a bit more idiomatic than the macro approach:

impl Writer {
    fn as_write(&mut self) -> &mut dyn Write {
        match self {
            Writer::File(f) => f,
            Writer::Stdout(s) => s,
        }
    }
}

@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 29, 2026

dyn is not acceptible.

@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 29, 2026

I would just move previous code to uucore.

@xtqqczze
Copy link
Copy Markdown
Contributor

impl Writer {
    fn with_write<T>(&mut self, f: impl FnOnce(&mut dyn Write) -> T) -> T {
        match self {
            Writer::File(w) => f(w),
            Writer::Stdout(w) => f(w),
        }
    }
}

Could quality is equivalent: https://rust.godbolt.org/z/f5bMhYfTY

@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 29, 2026

Is the optimization guaranteed for all Rust version and targets?

@oech3 oech3 closed this Apr 29, 2026
@oech3 oech3 deleted the tee-dispatch branch April 29, 2026 08:11
@xtqqczze
Copy link
Copy Markdown
Contributor

Can't use enum_dispatch crate.

@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 29, 2026

Hesitating to add new dep.

@xtqqczze
Copy link
Copy Markdown
Contributor

I would just move previous code to uucore.

Yeah, I think the duplication would be fine there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants