From a97acd8fa854a470f26e7c39a62b90f2e2c2c664 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 19 Apr 2020 17:59:32 +0200 Subject: Use `Borrow` when binding in `layer::Cache` --- wgpu/src/widget/canvas/layer/cache.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'wgpu') diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs index 2e87297c..e8d62b63 100644 --- a/wgpu/src/widget/canvas/layer/cache.rs +++ b/wgpu/src/widget/canvas/layer/cache.rs @@ -4,7 +4,7 @@ use crate::{ }; use iced_native::Size; -use std::{cell::RefCell, marker::PhantomData, sync::Arc}; +use std::{borrow::Borrow, cell::RefCell, marker::PhantomData, sync::Arc}; enum State { Empty, @@ -71,7 +71,10 @@ where /// [`Cache`]: struct.Cache.html /// [`Layer`]: ../trait.Layer.html /// [`Canvas`]: ../../struct.Canvas.html - pub fn with<'a>(&'a self, input: &'a T) -> impl Layer + 'a { + pub fn with<'a>( + &'a self, + input: impl Borrow + std::fmt::Debug + 'a, + ) -> impl Layer + 'a { Bind { cache: self, input: input, @@ -94,14 +97,15 @@ where } #[derive(Debug)] -struct Bind<'a, T: Drawable> { +struct Bind<'a, T: Drawable, I: Borrow + 'a> { cache: &'a Cache, - input: &'a T, + input: I, } -impl<'a, T> Layer for Bind<'a, T> +impl<'a, T, I> Layer for Bind<'a, T, I> where T: Drawable + std::fmt::Debug, + I: Borrow + std::fmt::Debug + 'a, { fn draw(&self, current_bounds: Size) -> Arc { use std::ops::Deref; @@ -115,7 +119,7 @@ where } let mut frame = Frame::new(current_bounds.width, current_bounds.height); - self.input.draw(&mut frame); + self.input.borrow().draw(&mut frame); let primitive = Arc::new(frame.into_primitive()); -- cgit