Conversation
|
What's your plan for handling |
#200 includes the overall plan that this PR is an offshoot from. The rough overview is to either use |
|
The changes to use specific enum variants for crate's own problems, like image dimensions too large, are fine. They're currently io::Error only to keep backwards compatibility. This crate could be released as 1.0 in the near future, and adding non_exhaustive error type is a good idea. However, I don't see how this path can lead to the crate actually being no-std compatible. You can move Vec to alloc, but if you can't get rid of io::Write, you can't use no-std. As far as I see, the other PR sill has std::io::Write. If you're going to provide a custom re-implementation/polyfill of std::io::Write, why not also provide a custom reimplementation of std::io::Error? That would reduce code changes elsewhere. I'm concerned about adding performance and code size overheads for std code. For example, for private helper functions that just call io::Write methods, wrapping the result in crate's error type is not beneficial. It only adds code bloat, and doesn't solve the compatibility problem of using io::Write. Perhaps another option would be to replace io::Write with some other trait for all users, including std users. |
The other PR allows
So that's actually what I've achieved here. Looking at just What this indirection buys us is the ability for a 3rd party to implement struct VecWriter(Vec<u8>);
impl image_gif::Write for VecWriter {
type Error = core::convert::Infallible;
fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
}Now when working with All of the above equally applied to |
|
Associated error type for Could you implement that? And keep |
|
Just an idea, but maybe there could be: struct NoStdEncoder<W: gif::Write> {…}
struct StdIoAdapter<W: io::Write> {…}
type Encoder<W> = NoStdEncoder<StdIoAdapter<W>>this way the |
197g
left a comment
There was a problem hiding this comment.
Agreed with @kornelski here, regardless of whether this leads to a no_std use or not the error cleanup itself is the right direction and non_exhaustive makes us more forward compatible. We can do a new major version bump without much of problem. (I'll have a look of whether the decoding loop could be modelled after png so that different readers can be integrated parallel to each other but that's beside this PR).
Objective
no_stdwill require independence fromstd::io::Error. Several usages could be trivially replaced by expandingDecodingErrorandEncodingErrorto include more specific error types. Additionally,LzwReader::decode_bytescurrently fails if the output buffer is of typeOutputBuffer::Vec, it'd be better for that code-path to be implemented.Solution
DecodingErrorandEncodingErrorasnon_exhaustiveto accommodate possible future changes in a non-breaking way.std::io::Errorand provide more detailed error information to consumers.OutputBuffer::Vecpath ofLzwReader::decode_bytesusingDecoder::into_vec.