Add into_inner() / try_into_inner() functions for SendCell

This commit is contained in:
Sebastian Dröge 2017-08-04 20:23:51 +03:00
parent 5676aeb3ef
commit 43a014b6fa

View file

@ -143,6 +143,19 @@ impl<T> SendCell<T> {
} }
} }
pub fn into_inner(self) -> T {
assert_eq!(thread::current().id(), self.thread_id);
self.data
}
pub fn try_into_inner(self) -> Result<T, Self> {
if thread::current().id() == self.thread_id {
Ok(self.data)
} else {
Err(self)
}
}
pub fn get(&self) -> &T { pub fn get(&self) -> &T {
assert_eq!(thread::current().id(), self.thread_id); assert_eq!(thread::current().id(), self.thread_id);
&self.data &self.data