Skip to content
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

Use Cow<'static, [u8]> in image/svg, add constructors taking &[u8]` #1453

Merged
merged 2 commits into from
Nov 5, 2022

Conversation

ids1024
Copy link
Contributor

@ids1024 ids1024 commented Oct 3, 2022

This should resolve #580 by providing a way to use an image included with include_bytes! without needing to copy it to a Vec to create an image handle.

It would be nice if these methods could also be const, but that isn't possible due to the hashing being done.

This is technically a breaking change since Handle::data() is public. But if that is used, it's most likely in used somewhere that only relies on the type derefing to &[u8].

This should resolve iced-rs#580 by
providing a way to use an image included with `include_bytes!` without
needing to copy it to a `Vec` to create an image handle.

It would be nice if these methods could also be `const`, but that isn't
possible due to the hashing being done.

This is technically a breaking change since `Handle::data()` is public.
But if that is used, it's most likely in used somewhere that only relies
on the type derefing to `&[u8]`.
@4gboframram
Copy link

About the constness issue, you could fix it yourself by using lazy_static, although it is naïve workaround and causes runtime overhead on the first dereference, but I agree that Handle should have this option.

@ids1024
Copy link
Contributor Author

ids1024 commented Oct 4, 2022

Yep. Or perhaps once_cell::sync::Lazy, which seems to be favored over lazy_static now (and is in the standard library now, but not yet stabilized). That is a general solution to things like this, but it would be more elegant to have a const constructor.

@hecrj hecrj added improvement An internal improvement widget svg image labels Nov 5, 2022
@hecrj hecrj added this to the 0.5.0 milestone Nov 5, 2022
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

We can leverage impl Into<Cow<'static, [u8]>> to avoid writing new methods and still keep backwards compatibility! Done that in bc5986c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bundle images
3 participants