You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My use-case is to stream directly from an rkyv serializer through zstd into a file (10MiB to 5GiB compressed). I'm using stream::Encoder to do that, and noticed it has this nice method available:
/// Return a recommendation for the size of data to write at once.pubfnrecommended_input_size() -> usize{[...]}
I going to assume rkyv may only arrive with a few bytes each, so I thought it would be best to use a BufWriter before feeding it into zstd, like that:
EDIT: It lowered compression time from 10s to 2s for 300MiB.
However the example above does not compile, as recommended_input_size is within an impl block of Encoder, which requires specifying the writer type as a generic. Even though the method internally does not care for the generic at all. So instead you have to do something like this, which doesn't feel like how it's intended to be used, especially since the generic is the wrong type anyway.
Indeed, it's a bit annoying having to specify a type here while it has no impact on what the function actually runs.
An alternative could be to make it a free function instead. It's currently available as zstd_safe::CCtx::in_size(), but we could re-export/wrap it under a better name (not sure what this name should be yet).
Alternatively we could implement this method just for a single instance of the generic type, for example Encoder<()>. It wouldn't be usable as a regular encoder, but rustc would be able to resolve Encoder::recommended_input_size like that.
My use-case is to stream directly from an rkyv serializer through zstd into a file (10MiB to 5GiB compressed). I'm using
stream::Encoder
to do that, and noticed it has this nice method available:I going to assume rkyv may only arrive with a few bytes each, so I thought it would be best to use a
BufWriter
before feeding it into zstd, like that:EDIT: It lowered compression time from 10s to 2s for 300MiB.
However the example above does not compile, as
recommended_input_size
is within an impl block ofEncoder
, which requires specifying the writer type as a generic. Even though the method internally does not care for the generic at all. So instead you have to do something like this, which doesn't feel like how it's intended to be used, especially since the generic is the wrong type anyway.The text was updated successfully, but these errors were encountered: