mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 18:38:21 -06:00
add a leak method
This commit is contained in:
parent
7e1f99d0a2
commit
59bf636236
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "fimg"
|
name = "fimg"
|
||||||
version = "0.4.17"
|
version = "0.4.19"
|
||||||
authors = ["bend-n <bend.n@outlook.com>"]
|
authors = ["bend-n <bend.n@outlook.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -475,6 +475,22 @@ impl<const CHANNELS: usize> Image<Vec<u8>, CHANNELS> {
|
||||||
buffer: vec![0; CHANNELS * width as usize * height as usize],
|
buffer: vec![0; CHANNELS * width as usize * height as usize],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Consumes and leaks this image, returning a reference to the image.
|
||||||
|
#[must_use = "not using the returned reference is a memory leak"]
|
||||||
|
pub fn leak(self) -> Image<&'static mut [u8], CHANNELS> {
|
||||||
|
// SAFETY: ctor
|
||||||
|
unsafe { Image::new(self.width, self.height, self.buffer.leak()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const CHANNELS: usize, T: ?Sized> Image<Box<T>, CHANNELS> {
|
||||||
|
/// Consumes and leaks this image, returning a reference to the image.
|
||||||
|
#[must_use = "not using the returned reference is a memory leak"]
|
||||||
|
pub fn leak(self) -> Image<&'static mut T, CHANNELS> {
|
||||||
|
// SAFETY: ctor
|
||||||
|
unsafe { Image::new(self.width, self.height, Box::leak(self.buffer)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// helper macro for defining the save() method.
|
/// helper macro for defining the save() method.
|
||||||
|
|
Loading…
Reference in a new issue