Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So far, the parse_xcursor() expected a byte slice as its input. Since the use of this crate is usually in reading cursor files, that means one has to first load the whole file to memory and then give the result to this crate, which copies some of that data.
For example, here is wayland-cursor using read_to_end() to load a file into memory and then passing the result to xcursor-rs:
https://github.com/Smithay/wayland-rs/blob/8fa95cfaae493f748d994ae2aee5433dd183e4ea/wayland-cursor/src/lib.rs#L250-L251
In this commit I want to change this. For API stability reasons, I am not touching parse_xcursor. Instead, a new function parse_xcursor_stream() is added. This function can be called with anything that implements both std::io::Read and Seek. The result is either a list of images or a std::io::Error. The existing parse_xcursor() simply forwards to this new function using std::io::Cursor.
All the parsing functions are changed to take a &mut impl Read. The internal StreamExt trait is changed to work on Read. Luckily, the use of Seek is so far contained in parse_xcursor_stream().
Since the new parse_xcursor_stream() function returns an std::io::Error, tag mismatches need to be turned into such an Error. For that, I simply used ErrorKind::Other with the text "Tag mismatch". This error is externally visible through this new function.
No behavioural changes to the code are intended.
Feel free to suggest another / a better file name for this new function, if you have some preference. I just went with the first thing that came to my mind.
Sadly, this PR conflicts with my other PR. If you like both PRs, I would prefer if this one is merged first, since it is the more complicated one. I can then update the other PR.