diff --git a/examples/src/bin/gtksink.rs b/examples/src/bin/gtksink.rs index 5da15d72a..7a4a6397d 100644 --- a/examples/src/bin/gtksink.rs +++ b/examples/src/bin/gtksink.rs @@ -85,7 +85,7 @@ fn create_ui(app: >k::Application) { let app_clone = SendCell::new(app.clone()); bus.add_watch(move |_, msg| { - let app = &app_clone; + let app = app_clone.borrow(); match msg.view() { MessageView::Eos(..) => gtk::main_quit(), MessageView::Error(err) => { @@ -95,7 +95,7 @@ fn create_ui(app: >k::Application) { err.get_error(), err.get_debug() ); - app.get().quit(); + app.quit(); } _ => (), }; @@ -127,6 +127,7 @@ fn main() { // but us having to use them in a closure that requires Send use std::thread; use std::cmp; +use std::ops; #[derive(Clone, Debug)] pub struct SendCell { @@ -154,6 +155,27 @@ impl SendCell { None } } + + pub fn borrow(&self) -> Ref { + Ref { data: self.get() } + } + + pub fn try_borrow(&self) -> Option> { + self.try_get().map(|data| Ref { data: data }) + } +} + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Ref<'a, T: 'a> { + data: &'a T, +} + +impl<'a, T: 'a> ops::Deref for Ref<'a, T> { + type Target = T; + + fn deref(&self) -> &T { + self.data + } } impl From for SendCell {