From c408b7863389aa2bdb253ffa363e693bcd02439f Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 19 Aug 2015 16:03:59 +0200 Subject: Move the Borrow and BorrowMut traits to libcore. --- src/liballoc/arc.rs | 5 +++++ src/liballoc/boxed.rs | 8 ++++++++ src/liballoc/rc.rs | 5 +++++ 3 files changed, 18 insertions(+) (limited to 'src/liballoc') 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 borrow::Borrow for Arc { + 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 Clone for Box<[T]> { } } +impl borrow::Borrow for Box { + fn borrow(&self) -> &T { &**self } +} + +impl borrow::BorrowMut for Box { + 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 borrow::Borrow for Rc { + fn borrow(&self) -> &T { &**self } +} -- cgit 1.4.1-3-g733a5