about summary refs log tree commit diff
path: root/src/libstd/cell.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-01-22 14:03:02 -0500
committerNiko Matsakis <niko@alum.mit.edu>2014-01-31 21:18:48 -0500
commit81d8328517a6a2830438aaec1d7e747156b13be0 (patch)
tree5f3337bdc79406fd7da088d146ad1f64a56ff83b /src/libstd/cell.rs
parent83f0f6ef6cb44d9fbba24372f223561a75a50c18 (diff)
Introduce marker types for indicating variance and for opting out
of builtin bounds.

Fixes #10834.
Fixes #11385.
cc #5922.
Diffstat (limited to 'src/libstd/cell.rs')
-rw-r--r--src/libstd/cell.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs
index 62fc08fd9d3..eb7d62b7bd3 100644
--- a/src/libstd/cell.rs
+++ b/src/libstd/cell.rs
@@ -13,19 +13,22 @@
 use prelude::*;
 use cast;
 use util::NonCopyable;
+use kinds::{marker,Pod};
 
 /// A mutable memory location that admits only `Pod` data.
-#[no_freeze]
-#[deriving(Clone)]
 pub struct Cell<T> {
     priv value: T,
+    priv marker1: marker::InvariantType<T>,
+    priv marker2: marker::NoFreeze,
 }
 
-impl<T: ::kinds::Pod> Cell<T> {
+impl<T:Pod> Cell<T> {
     /// Creates a new `Cell` containing the given value.
     pub fn new(value: T) -> Cell<T> {
         Cell {
             value: value,
+            marker1: marker::InvariantType::<T>,
+            marker2: marker::NoFreeze,
         }
     }
 
@@ -44,12 +47,19 @@ impl<T: ::kinds::Pod> Cell<T> {
     }
 }
 
+impl<T:Pod> Clone for Cell<T> {
+    fn clone(&self) -> Cell<T> {
+        Cell::new(self.get())
+    }
+}
+
 /// A mutable memory location with dynamically checked borrow rules
-#[no_freeze]
 pub struct RefCell<T> {
     priv value: T,
     priv borrow: BorrowFlag,
-    priv nc: NonCopyable
+    priv nc: NonCopyable,
+    priv marker1: marker::InvariantType<T>,
+    priv marker2: marker::NoFreeze,
 }
 
 // Values [1, MAX-1] represent the number of `Ref` active
@@ -62,6 +72,8 @@ impl<T> RefCell<T> {
     /// Create a new `RefCell` containing `value`
     pub fn new(value: T) -> RefCell<T> {
         RefCell {
+            marker1: marker::InvariantType::<T>,
+            marker2: marker::NoFreeze,
             value: value,
             borrow: UNUSED,
             nc: NonCopyable