Auto merge of #26008 - Marwes:arc_rc_as_ref, r=alexcrichton

The implementations are straightforward, I only hope I got the stability attributes correct(?).
This commit is contained in:
bors 2015-06-05 08:30:33 +00:00
commit ef72938a8b
2 changed files with 19 additions and 0 deletions

View File

@ -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>`.
///

View File

@ -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>`.