Unify methods by leveraging Into<Cow> in image and svg

This commit is contained in:
Héctor Ramón Jiménez 2022-11-05 01:53:24 +01:00
parent 6ce12fc0c6
commit bc5986c7c6
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 7 additions and 32 deletions

View file

@ -25,15 +25,8 @@ impl Handle {
///
/// This is useful if you already have your SVG data in-memory, maybe
/// because you downloaded or generated it procedurally.
pub fn from_memory(bytes: impl Into<Vec<u8>>) -> Handle {
Self::from_data(Data::Bytes(Cow::Owned(bytes.into())))
}
/// Like [`Handle::from_memory`], but from static image data.
///
/// Useful for images included in binary, for instance with [`include_bytes!`].
pub fn from_static_memory(bytes: &'static [u8]) -> Handle {
Self::from_data(Data::Bytes(Cow::Borrowed(bytes)))
pub fn from_memory(bytes: impl Into<Cow<'static, [u8]>>) -> Handle {
Self::from_data(Data::Bytes(bytes.into()))
}
fn from_data(data: Data) -> Handle {