From e8166dd3e4f8ceacd63abff39dcbc8fab1cb8564 Mon Sep 17 00:00:00 2001 From: Thomas Sieverding Date: Sun, 7 Apr 2024 18:36:47 -0700 Subject: [PATCH] Utilize bytes::Bytes iced_runtime::window::Screenshot --- runtime/Cargo.toml | 1 + runtime/src/window/screenshot.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 2150346202..703c3ed955 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 21e0471888..bd277ddfcb 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>, + pub bytes: Bytes, /// The size of the [`Screenshot`]. pub size: Size, } @@ -28,9 +28,9 @@ impl Debug for Screenshot { impl Screenshot { /// Creates a new [`Screenshot`]. - pub fn new(bytes: Vec, size: Size) -> Self { + pub fn new(bytes: impl Into, size: Size) -> 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 Into for Screenshot { + fn into(self) -> Bytes { + self.bytes + } +} + #[derive(Debug, thiserror::Error)] /// Errors that can occur when cropping a [`Screenshot`]. pub enum CropError {