From 64106c4d3d4ddba8c7bc2af75376e6d3d3d75601 Mon Sep 17 00:00:00 2001 From: Date: Mon, 29 Jun 2015 20:16:15 +0000 Subject: Update documentation --- src/carboxyl/readonly.rs.html | 173 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/carboxyl/readonly.rs.html (limited to 'src/carboxyl/readonly.rs.html') diff --git a/src/carboxyl/readonly.rs.html b/src/carboxyl/readonly.rs.html new file mode 100644 index 0000000..84fce7f --- /dev/null +++ b/src/carboxyl/readonly.rs.html @@ -0,0 +1,173 @@ + + + + + + + + + + readonly.rs.html -- source + + + + + + + + + + + + + + + +
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+
+//! Thread-safe read-only smart pointer.
+
+use std::sync::{ Arc, RwLock, RwLockReadGuard };
+use std::ops::Deref;
+
+/// Guards read-access into a read-only pointer.
+pub struct ReadOnlyGuard<'a, T: 'a> {
+    guard: RwLockReadGuard<'a, T>,
+}
+
+impl<'a, T> Deref for ReadOnlyGuard<'a, T> {
+    type Target = T;
+    fn deref(&self) -> &T { &self.guard }
+}
+
+/// A thread-safe read-only smart pointer.
+pub struct ReadOnly<T> {
+    ptr: Arc<RwLock<T>>,
+}
+
+impl<T> Clone for ReadOnly<T> {
+    fn clone(&self) -> ReadOnly<T> {
+        ReadOnly { ptr: self.ptr.clone() }
+    }
+}
+
+/// Create a new read-only pointer.
+pub fn create<T>(ptr: Arc<RwLock<T>>) -> ReadOnly<T> { ReadOnly { ptr: ptr } }
+
+impl<T> ReadOnly<T> {
+    /// Gain read-access to the stored value.
+    ///
+    /// In case, the underlying data structure has been poisoned, it returns
+    /// `None`.
+    pub fn read(&self) -> Option<ReadOnlyGuard<T>> {
+        self.ptr.read().ok().map(|g| ReadOnlyGuard { guard: g })
+    }
+}
+
+
+ + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3