about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2015-08-19 16:03:59 +0200
committerSimon Sapin <simon.sapin@exyr.org>2015-08-22 13:58:39 +0200
commitc408b7863389aa2bdb253ffa363e693bcd02439f (patch)
treed24554daf2d34ade8df07a7a68c4a5ced316cf0b /src/liballoc
parent94ee3b5a54a9f4965b82f5e4eda512966e96ac63 (diff)
downloadrust-c408b7863389aa2bdb253ffa363e693bcd02439f.tar.gz
rust-c408b7863389aa2bdb253ffa363e693bcd02439f.zip
Move the Borrow and BorrowMut traits to libcore.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs5
-rw-r--r--src/liballoc/boxed.rs8
-rw-r--r--src/liballoc/rc.rs5
3 files changed, 18 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index bb2daa2a1d7..b68d7976540 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -73,6 +73,7 @@ use boxed::Box;
 
 use core::sync::atomic;
 use core::sync::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
+use core::borrow;
 use core::fmt;
 use core::cmp::Ordering;
 use core::mem::{align_of_val, size_of_val};
@@ -1109,3 +1110,7 @@ mod tests {
         assert!(y.upgrade().is_none());
     }
 }
+
+impl<T: ?Sized> borrow::Borrow<T> for Arc<T> {
+    fn borrow(&self) -> &T { &**self }
+}
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index e3019f952fe..a6e0f3a9bd9 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -57,6 +57,7 @@ use heap;
 use raw_vec::RawVec;
 
 use core::any::Any;
+use core::borrow;
 use core::cmp::Ordering;
 use core::fmt;
 use core::hash::{self, Hash};
@@ -562,3 +563,10 @@ impl<T: Clone> Clone for Box<[T]> {
     }
 }
 
+impl<T: ?Sized> borrow::Borrow<T> for Box<T> {
+    fn borrow(&self) -> &T { &**self }
+}
+
+impl<T: ?Sized> borrow::BorrowMut<T> for Box<T> {
+    fn borrow_mut(&mut self) -> &mut T { &mut **self }
+}
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 9649d0f71a1..b1fb5be4d21 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -158,6 +158,7 @@ use boxed::Box;
 #[cfg(test)]
 use std::boxed::Box;
 
+use core::borrow;
 use core::cell::Cell;
 use core::cmp::Ordering;
 use core::fmt;
@@ -1091,3 +1092,7 @@ mod tests {
         assert_eq!(foo, foo.clone());
     }
 }
+
+impl<T: ?Sized> borrow::Borrow<T> for Rc<T> {
+    fn borrow(&self) -> &T { &**self }
+}