diff options
author | 2022-11-05 01:53:24 +0100 | |
---|---|---|
committer | 2022-11-05 01:53:24 +0100 | |
commit | bc5986c7c69efd206b900e8d923d3df3a225f6cc (patch) | |
tree | 00fd02ea216ad6b43b7b80d932fbf4181c15d481 | |
parent | 6ce12fc0c60adbd169676ee985e8529831633a76 (diff) | |
download | iced-bc5986c7c69efd206b900e8d923d3df3a225f6cc.tar.gz iced-bc5986c7c69efd206b900e8d923d3df3a225f6cc.tar.bz2 iced-bc5986c7c69efd206b900e8d923d3df3a225f6cc.zip |
Unify methods by leveraging `Into<Cow>` in `image` and `svg`
-rw-r--r-- | native/src/image.rs | 28 | ||||
-rw-r--r-- | native/src/svg.rs | 11 |
2 files changed, 7 insertions, 32 deletions
diff --git a/native/src/image.rs b/native/src/image.rs index 41e41aa4..b849ef84 100644 --- a/native/src/image.rs +++ b/native/src/image.rs @@ -26,26 +26,15 @@ impl Handle { /// pixels. /// /// This is useful if you have already decoded your image. - pub fn from_pixels(width: u32, height: u32, pixels: Vec<u8>) -> Handle { - Self::from_data(Data::Pixels { - width, - height, - pixels: Cow::Owned(pixels), - }) - } - - /// Like [`Handle::from_pixels`], but from static pixel data. - /// - /// Useful for images included in binary, for instance with [`include_bytes!`]. - pub fn from_static_pixels( + pub fn from_pixels( width: u32, height: u32, - pixels: &'static [u8], + pixels: impl Into<Cow<'static, [u8]>>, ) -> Handle { Self::from_data(Data::Pixels { width, height, - pixels: Cow::Borrowed(pixels), + pixels: pixels.into(), }) } @@ -55,15 +44,8 @@ impl Handle { /// /// This is useful if you already have your image loaded in-memory, maybe /// because you downloaded or generated it procedurally. - pub fn from_memory(bytes: Vec<u8>) -> Handle { - Self::from_data(Data::Bytes(Cow::Owned(bytes))) - } - - /// 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 { diff --git a/native/src/svg.rs b/native/src/svg.rs index c89eed3f..d4d20182 100644 --- a/native/src/svg.rs +++ b/native/src/svg.rs @@ -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 { |