-
Notifications
You must be signed in to change notification settings - Fork 8
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 declarative macro to implement formats #67
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #67 +/- ##
==========================================
- Coverage 90.89% 90.23% -0.66%
==========================================
Files 10 10
Lines 1010 942 -68
==========================================
- Hits 918 850 -68
Misses 92 92 ☔ View full report in Codecov by Sentry. |
crate::send::compression::Format::Gzip, | ||
flate2::write::GzEncoder::new, | ||
flate2::read::MultiGzDecoder::new, | ||
std::io::Read | Send, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This |
is a bit weird, I wanted +
but that is not available syntax for a path
More info: https://internals.rust-lang.org/t/allow-to-follow-path-fragments-in-declarative-macros/13676
gz, | ||
"gz", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level: Level, | ||
) -> Result<Box<dyn io::Write + Send + 'a>, Error> { | ||
Ok(Box::new( | ||
zstd::stream::write::Encoder::new(out, level.into())?.auto_finish(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't do zstd
because it has the extra .auto_finish()
, need to look more into it
cfg_if! { | ||
if #[cfg(feature = "zstd")] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out we don't need cfg_if!
, #[cfg(feature = "zstd")]
and #[cfg(not(feature = "zstd"))]
are enough for our use case
compression::Format::Zstd => compression::new_zstd_encoder(out_stream, level), | ||
compression::Format::Gzip => compression::gz::encoder(out_stream, level), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now each format is a submodule instead of a function, and all submodules have an encoder
and a decoder
function. These are all private, so it doesn't break the public API
Very good idea and work, if you need/want help just ask. |
fa4936c
to
9df5d8f
Compare
CodSpeed Performance ReportMerging #67 will not alter performanceComparing Summary
|
Trying out a declarative macro to reduce copy-and-paste between
basic
andsend
modules.