impl boxed for &[u8]

This commit is contained in:
bendn 2023-10-05 09:43:50 +07:00
parent 1c218cd1a9
commit 06fc71d4bc
No known key found for this signature in database
GPG key ID: 0D9D3A2A3B2A93D6
2 changed files with 8 additions and 1 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "fimg" name = "fimg"
version = "0.4.14" version = "0.4.15"
authors = ["bend-n <bend.n@outlook.com>"] authors = ["bend-n <bend.n@outlook.com>"]
license = "MIT" license = "MIT"
edition = "2021" edition = "2021"

View file

@ -251,6 +251,13 @@ impl<const CHANNELS: usize, const N: usize> Image<[u8; N], CHANNELS> {
} }
} }
impl<const CHANNELS: usize> Image<&[u8], CHANNELS> {
/// Box this image.
pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> {
unsafe { Image::new(self.width, self.height, self.buffer.into()) }
}
}
impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> { impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> {
/// Box this owned image. /// Box this owned image.
pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> { pub fn boxed(self) -> Image<Box<[u8]>, CHANNELS> {