From 43a014b6fae40bf317b44d606afebb4bb309bc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 4 Aug 2017 20:23:51 +0300 Subject: [PATCH] Add into_inner() / try_into_inner() functions for SendCell --- examples/src/bin/gtksink.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/src/bin/gtksink.rs b/examples/src/bin/gtksink.rs index 7a4a6397d..f756109b6 100644 --- a/examples/src/bin/gtksink.rs +++ b/examples/src/bin/gtksink.rs @@ -143,6 +143,19 @@ impl SendCell { } } + pub fn into_inner(self) -> T { + assert_eq!(thread::current().id(), self.thread_id); + self.data + } + + pub fn try_into_inner(self) -> Result { + if thread::current().id() == self.thread_id { + Ok(self.data) + } else { + Err(self) + } + } + pub fn get(&self) -> &T { assert_eq!(thread::current().id(), self.thread_id); &self.data