diff options
author | 2020-04-19 17:59:32 +0200 | |
---|---|---|
committer | 2020-04-19 17:59:32 +0200 | |
commit | a97acd8fa854a470f26e7c39a62b90f2e2c2c664 (patch) | |
tree | 90ffef03082d4c9137212d7765c4c34c68a6c1df /wgpu | |
parent | 8ade09a0f6fd6bfdcefebb92ccbbff25d741062a (diff) | |
download | iced-a97acd8fa854a470f26e7c39a62b90f2e2c2c664.tar.gz iced-a97acd8fa854a470f26e7c39a62b90f2e2c2c664.tar.bz2 iced-a97acd8fa854a470f26e7c39a62b90f2e2c2c664.zip |
Use `Borrow<T>` when binding in `layer::Cache<T>`
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/widget/canvas/layer/cache.rs | 16 |
1 files changed, 10 insertions, 6 deletions
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<T> + 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<T> + 'a> { cache: &'a Cache<T>, - 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<T> + std::fmt::Debug + 'a, { fn draw(&self, current_bounds: Size) -> Arc<Primitive> { 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()); |