iced icon indicating copy to clipboard operation
iced copied to clipboard

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

Open ids1024 opened this issue 1 year ago • 2 comments

This should resolve https://github.com/iced-rs/iced/issues/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].

ids1024 avatar Oct 03 '22 22:10 ids1024

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.

4gboframram avatar Oct 04 '22 10:10 4gboframram

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.

ids1024 avatar Oct 04 '22 14:10 ids1024