-
Notifications
You must be signed in to change notification settings - Fork 7
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: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #67 +/- ##
==========================================
- Coverage 81.57% 76.41% -5.16%
==========================================
Files 12 12
Lines 266 229 -37
==========================================
- Hits 217 175 -42
- Misses 49 54 +5 ☔ 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. |
Trying out a declarative macro to reduce copy-and-paste between
basic
andsend
modules.