Unify methods by leveraging Into<Cow> in image and svg
This commit is contained in:
parent
6ce12fc0c6
commit
bc5986c7c6
2 changed files with 7 additions and 32 deletions
|
|
@ -26,26 +26,15 @@ impl Handle {
|
||||||
/// pixels.
|
/// pixels.
|
||||||
///
|
///
|
||||||
/// This is useful if you have already decoded your image.
|
/// This is useful if you have already decoded your image.
|
||||||
pub fn from_pixels(width: u32, height: u32, pixels: Vec<u8>) -> Handle {
|
pub fn from_pixels(
|
||||||
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(
|
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
pixels: &'static [u8],
|
pixels: impl Into<Cow<'static, [u8]>>,
|
||||||
) -> Handle {
|
) -> Handle {
|
||||||
Self::from_data(Data::Pixels {
|
Self::from_data(Data::Pixels {
|
||||||
width,
|
width,
|
||||||
height,
|
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
|
/// This is useful if you already have your image loaded in-memory, maybe
|
||||||
/// because you downloaded or generated it procedurally.
|
/// because you downloaded or generated it procedurally.
|
||||||
pub fn from_memory(bytes: Vec<u8>) -> Handle {
|
pub fn from_memory(bytes: impl Into<Cow<'static, [u8]>>) -> Handle {
|
||||||
Self::from_data(Data::Bytes(Cow::Owned(bytes)))
|
Self::from_data(Data::Bytes(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)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_data(data: Data) -> Handle {
|
fn from_data(data: Data) -> Handle {
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,8 @@ impl Handle {
|
||||||
///
|
///
|
||||||
/// This is useful if you already have your SVG data in-memory, maybe
|
/// This is useful if you already have your SVG data in-memory, maybe
|
||||||
/// because you downloaded or generated it procedurally.
|
/// because you downloaded or generated it procedurally.
|
||||||
pub fn from_memory(bytes: impl Into<Vec<u8>>) -> Handle {
|
pub fn from_memory(bytes: impl Into<Cow<'static, [u8]>>) -> Handle {
|
||||||
Self::from_data(Data::Bytes(Cow::Owned(bytes.into())))
|
Self::from_data(Data::Bytes(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)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_data(data: Data) -> Handle {
|
fn from_data(data: Data) -> Handle {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue