-
Notifications
You must be signed in to change notification settings - Fork 43
Tidy std::io::Error
Usage
#202
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
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 |
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.
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_std
will require independence fromstd::io::Error
. Several usages could be trivially replaced by expandingDecodingError
andEncodingError
to include more specific error types. Additionally,LzwReader::decode_bytes
currently fails if the output buffer is of typeOutputBuffer::Vec
, it'd be better for that code-path to be implemented.Solution
DecodingError
andEncodingError
asnon_exhaustive
to accommodate possible future changes in a non-breaking way.std::io::Error
and provide more detailed error information to consumers.OutputBuffer::Vec
path ofLzwReader::decode_bytes
usingDecoder::into_vec
.