diff options
| author | bors <bors@rust-lang.org> | 2015-06-05 08:30:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-06-05 08:30:33 +0000 |
| commit | ef72938a8b9171abc5c4b463d3e8345dc0e603a6 (patch) | |
| tree | c1ae5004718b48a1aa2204fb891a10c5f7ea5dc5 | |
| parent | d95df9a3a9fe83fbe8e9d6ecdd5dcd8aec3f42e4 (diff) | |
| parent | 7f3ae0aa26d24100379ae0f3eef29916a32f4e79 (diff) | |
| download | rust-ef72938a8b9171abc5c4b463d3e8345dc0e603a6.tar.gz rust-ef72938a8b9171abc5c4b463d3e8345dc0e603a6.zip | |
Auto merge of #26008 - Marwes:arc_rc_as_ref, r=alexcrichton
The implementations are straightforward, I only hope I got the stability attributes correct(?).
| -rw-r--r-- | src/liballoc/arc.rs | 9 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 10 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 593ecc72d50..d12d28335dd 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -332,6 +332,15 @@ impl<T: ?Sized> Deref for Arc<T> { } } +#[stable(feature = "rc_arc_as_ref", since = "1.2.0")] +impl<T: ?Sized> AsRef<T> for Arc<T> { + + #[inline] + fn as_ref(&self) -> &T { + &self.inner().data + } +} + impl<T: Clone> Arc<T> { /// Make a mutable reference from the given `Arc<T>`. /// diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 44f4a6a6290..906a41a4d53 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -156,6 +156,7 @@ use std::boxed; use core::cell::Cell; use core::clone::Clone; use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering}; +use core::convert::AsRef; use core::default::Default; use core::fmt; use core::hash::{Hasher, Hash}; @@ -379,6 +380,15 @@ impl<T: ?Sized> Deref for Rc<T> { } } +#[stable(feature = "rc_arc_as_ref", since = "1.2.0")] +impl<T: ?Sized> AsRef<T> for Rc<T> { + + #[inline(always)] + fn as_ref(&self) -> &T { + &self.inner().value + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized> Drop for Rc<T> { /// Drops the `Rc<T>`. |
