diff options
author | 2024-05-01 06:57:38 +0200 | |
---|---|---|
committer | 2024-05-01 06:57:38 +0200 | |
commit | a11784f9edfd5668fa998b2a7d2a50971a4cdac5 (patch) | |
tree | 0ec25d8bcbf4bff4bf7e9ee9c9e462ef2f47af3a /runtime | |
parent | 89892f1760d4ec67f458d67ae722c3f06d524a1b (diff) | |
parent | 01b014c19fa2a3c200fb2077e31822f525f729cf (diff) | |
download | iced-a11784f9edfd5668fa998b2a7d2a50971a4cdac5.tar.gz iced-a11784f9edfd5668fa998b2a7d2a50971a4cdac5.tar.bz2 iced-a11784f9edfd5668fa998b2a7d2a50971a4cdac5.zip |
Merge pull request #2356 from Bajix/feature/bytes
Utilize bytes::Bytes for images
Diffstat (limited to '')
-rw-r--r-- | runtime/Cargo.toml | 1 | ||||
-rw-r--r-- | runtime/src/window/screenshot.rs | 16 |
2 files changed, 12 insertions, 5 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 21503462..703c3ed9 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -18,6 +18,7 @@ debug = [] multi-window = [] [dependencies] +bytes.workspace = true iced_core.workspace = true iced_futures.workspace = true iced_futures.features = ["thread-pool"] diff --git a/runtime/src/window/screenshot.rs b/runtime/src/window/screenshot.rs index 21e04718..fb318110 100644 --- a/runtime/src/window/screenshot.rs +++ b/runtime/src/window/screenshot.rs @@ -1,8 +1,8 @@ //! Take screenshots of a window. use crate::core::{Rectangle, Size}; +use bytes::Bytes; use std::fmt::{Debug, Formatter}; -use std::sync::Arc; /// Data of a screenshot, captured with `window::screenshot()`. /// @@ -10,7 +10,7 @@ use std::sync::Arc; #[derive(Clone)] pub struct Screenshot { /// The bytes of the [`Screenshot`]. - pub bytes: Arc<Vec<u8>>, + pub bytes: Bytes, /// The size of the [`Screenshot`]. pub size: Size<u32>, } @@ -28,9 +28,9 @@ impl Debug for Screenshot { impl Screenshot { /// Creates a new [`Screenshot`]. - pub fn new(bytes: Vec<u8>, size: Size<u32>) -> Self { + pub fn new(bytes: impl Into<Bytes>, size: Size<u32>) -> Self { Self { - bytes: Arc::new(bytes), + bytes: bytes.into(), size, } } @@ -68,7 +68,7 @@ impl Screenshot { ); Ok(Self { - bytes: Arc::new(chopped), + bytes: Bytes::from(chopped), size: Size::new(region.width, region.height), }) } @@ -80,6 +80,12 @@ impl AsRef<[u8]> for Screenshot { } } +impl From<Screenshot> for Bytes { + fn from(screenshot: Screenshot) -> Self { + screenshot.bytes + } +} + #[derive(Debug, thiserror::Error)] /// Errors that can occur when cropping a [`Screenshot`]. pub enum CropError { |