From 7c084d96958f1dacf9efae1f983bb44086fb70dc Mon Sep 17 00:00:00 2001 From: Thomas Sieverding Date: Sun, 7 Apr 2024 18:36:47 -0700 Subject: Utilize bytes::Bytes iced_runtime::window::Screenshot --- runtime/src/window/screenshot.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'runtime/src/window/screenshot.rs') diff --git a/runtime/src/window/screenshot.rs b/runtime/src/window/screenshot.rs index 21e04718..bd277ddf 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 { -- cgit From f5bc336d699d0c6440f6d638a5a437baaabe1e43 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 May 2024 01:09:31 +0200 Subject: Fix `clippy` lint in `runtime::window::screenshot` --- runtime/src/window/screenshot.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/src/window/screenshot.rs') diff --git a/runtime/src/window/screenshot.rs b/runtime/src/window/screenshot.rs index bd277ddf..fb318110 100644 --- a/runtime/src/window/screenshot.rs +++ b/runtime/src/window/screenshot.rs @@ -80,9 +80,9 @@ impl AsRef<[u8]> for Screenshot { } } -impl Into for Screenshot { - fn into(self) -> Bytes { - self.bytes +impl From for Bytes { + fn from(screenshot: Screenshot) -> Self { + screenshot.bytes } } -- cgit