From 6e7769b65dfda1ab748eb26f8832fd32714f6fc1 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 8 Apr 2020 23:07:42 +0100 Subject: [PATCH] impl default for canvas cache --- examples/clock/src/main.rs | 2 +- examples/solar_system/src/main.rs | 2 +- wgpu/src/widget/canvas/layer/cache.rs | 31 +++++++++++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index 88f8322c..a85a964c 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -29,7 +29,7 @@ impl Application for Clock { ( Clock { now: chrono::Local::now().into(), - clock: canvas::layer::Cache::new(), + clock: Default::default(), }, Command::none(), ) diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 1967b7c5..963f047b 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -39,7 +39,7 @@ impl Application for SolarSystem { ( SolarSystem { state: State::new(), - solar_system: canvas::layer::Cache::new(), + solar_system: Default::default(), }, Command::none(), ) diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs index 20a095bd..4f8c2bec 100644 --- a/wgpu/src/widget/canvas/layer/cache.rs +++ b/wgpu/src/widget/canvas/layer/cache.rs @@ -6,6 +6,19 @@ use crate::{ use iced_native::Size; use std::{cell::RefCell, marker::PhantomData, sync::Arc}; +enum State { + Empty, + Filled { + bounds: Size, + primitive: Arc, + }, +} + +impl Default for State { + fn default() -> Self { + State::Empty + } +} /// A simple cache that stores generated geometry to avoid recomputation. /// /// A [`Cache`] will not redraw its geometry unless the dimensions of its layer @@ -19,12 +32,16 @@ pub struct Cache { state: RefCell, } -enum State { - Empty, - Filled { - bounds: Size, - primitive: Arc, - }, +impl Default for Cache +where + T: Drawable, +{ + fn default() -> Self { + Self { + input: PhantomData, + state: Default::default(), + } + } } impl Cache @@ -37,7 +54,7 @@ where pub fn new() -> Self { Cache { input: PhantomData, - state: RefCell::new(State::Empty), + state: Default::default(), } }