-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
image: Allow any kind of data that implements AsRef<[u8]>
for the i…
#1551
Conversation
Image handle already uses an arc Line 11 in 370fa14
https://github.com/iced-rs/iced/blob/master/examples/pokedex/src/main.rs#L113 |
Ah I see, thanks! Then this can also become a plain Is the |
2ebb688
to
0ae1342
Compare
0ae1342
to
2009e68
Compare
…mage data It's not required anywhere for it to be a plain slice or a `Vec` and this makes it possible to use data allocated in a different way without copying.
2009e68
to
d7c8308
Compare
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.
Thanks for this!
I have moved the Arc
from Handle
to Bytes
since the other fields in Data
should be fairly cheap to Clone
and we can get rid of the awkward trait this way.
ImageBytes(self.0.clone_boxed()) | ||
impl Bytes { | ||
/// Creates new [`Bytes`] around `data`. | ||
pub fn new(data: impl AsRef<[u8]> + Clone + Send + Sync + 'static) -> Self { |
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.
You don't really need the Clone
here anymore as the Arc
already gives you that :)
Do you want me to submit a PR for removing the trait bound or will you take care of the change?
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.
Good catch. Just opened #1717.
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.
Thanks!
…mage data
It's not required anywhere for it to be a plain slice or a
Vec
and this makes it possible to use data allocated in a different way without copying.Also store the data in an
Arc
to allow cheap cloning.