From 6e7769b65dfda1ab748eb26f8832fd32714f6fc1 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 8 Apr 2020 23:07:42 +0100 Subject: impl default for canvas cache --- wgpu/src/widget/canvas/layer/cache.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'wgpu') 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(), } } -- cgit