diff options
author | 2023-06-06 16:14:42 +0200 | |
---|---|---|
committer | 2023-06-06 16:14:42 +0200 | |
commit | 5324928044cba800454b1861eb9999038bc28c2e (patch) | |
tree | 35f64a1514422830d271f122791dfa04a53eaaeb /runtime/src | |
parent | 7adfaa88a68e1accfaddf13e82b8bd7a11ee8786 (diff) | |
download | iced-5324928044cba800454b1861eb9999038bc28c2e.tar.gz iced-5324928044cba800454b1861eb9999038bc28c2e.tar.bz2 iced-5324928044cba800454b1861eb9999038bc28c2e.zip |
Wrap `Screenshot::bytes` in an `Arc` and implement `AsRef<[u8]>`
Diffstat (limited to 'runtime/src')
-rw-r--r-- | runtime/src/screenshot.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/runtime/src/screenshot.rs b/runtime/src/screenshot.rs index 527e400f..b88f2c20 100644 --- a/runtime/src/screenshot.rs +++ b/runtime/src/screenshot.rs @@ -1,5 +1,7 @@ -use iced_core::{Rectangle, Size}; +use crate::core::{Rectangle, Size}; + use std::fmt::{Debug, Formatter}; +use std::sync::Arc; /// Data of a screenshot, captured with `window::screenshot()`. /// @@ -7,7 +9,7 @@ use std::fmt::{Debug, Formatter}; #[derive(Clone)] pub struct Screenshot { /// The bytes of the [`Screenshot`]. - pub bytes: Vec<u8>, + pub bytes: Arc<Vec<u8>>, /// The size of the [`Screenshot`]. pub size: Size<u32>, } @@ -26,7 +28,10 @@ impl Debug for Screenshot { impl Screenshot { /// Creates a new [`Screenshot`]. pub fn new(bytes: Vec<u8>, size: Size<u32>) -> Self { - Self { bytes, size } + Self { + bytes: Arc::new(bytes), + size, + } } /// Crops a [`Screenshot`] to the provided `region`. This will always be relative to the @@ -62,12 +67,18 @@ impl Screenshot { ); Ok(Self { - bytes: chopped, + bytes: Arc::new(chopped), size: Size::new(region.width, region.height), }) } } +impl AsRef<[u8]> for Screenshot { + fn as_ref(&self) -> &[u8] { + &self.bytes + } +} + #[derive(Debug, thiserror::Error)] /// Errors that can occur when cropping a [`Screenshot`]. pub enum CropError { |