about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-11-26 16:12:47 -0800
committerBrian Anderson <banderson@mozilla.com>2012-11-27 11:08:19 -0800
commitb21e9d52de543d0beb30a1043aa40a9015453d6f (patch)
tree88d0dd1d147359aa15ec2ff868a685e48d88de0f /src/libcore
parent1c348e6e3832b1fd8282be696f76ac3c50115162 (diff)
core: Add Clone trait
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/clone.rs10
-rw-r--r--src/libcore/core.rc1
-rw-r--r--src/libcore/core.rs4
-rw-r--r--src/libcore/private.rs6
4 files changed, 19 insertions, 2 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs
new file mode 100644
index 00000000000..8e180ff3414
--- /dev/null
+++ b/src/libcore/clone.rs
@@ -0,0 +1,10 @@
+/**
+Clonable types are copied with the clone method
+*/
+pub trait Clone {
+    fn clone(&self) -> self;
+}
+
+impl (): Clone {
+    fn clone(&self) -> () { () }
+}
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index 707d6125046..5dbb0fcdb56 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -156,6 +156,7 @@ pub mod to_str;
 pub mod to_bytes;
 pub mod from_str;
 pub mod util;
+pub mod clone;
 
 // Data structure modules
 
diff --git a/src/libcore/core.rs b/src/libcore/core.rs
index 4bc04566740..c9157a8d254 100644
--- a/src/libcore/core.rs
+++ b/src/libcore/core.rs
@@ -48,6 +48,10 @@ pub use coreops::ops::{BitXor};
 #[cfg(test)]
 pub use coreops::ops::{Shl, Shr, Index};
 
+#[cfg(notest)]
+pub use clone::Clone;
+#[cfg(test)]
+pub use coreops::clone::Clone;
 
 // Export the log levels as global constants. Higher levels mean
 // more-verbosity. Error is the bottom level, default logging level is
diff --git a/src/libcore/private.rs b/src/libcore/private.rs
index 98fcad94c1e..bf640656267 100644
--- a/src/libcore/private.rs
+++ b/src/libcore/private.rs
@@ -509,12 +509,14 @@ pub fn exclusive<T:Send >(user_data: T) -> Exclusive<T> {
     Exclusive { x: unsafe { shared_mutable_state(move data) } }
 }
 
-impl<T: Send> Exclusive<T> {
+impl<T: Send> Exclusive<T>: Clone {
     // Duplicate an exclusive ARC, as std::arc::clone.
-    fn clone() -> Exclusive<T> {
+    fn clone(&self) -> Exclusive<T> {
         Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
     }
+}
 
+impl<T: Send> Exclusive<T> {
     // Exactly like std::arc::mutex_arc,access(), but with the little_lock
     // instead of a proper mutex. Same reason for being unsafe.
     //