]> git.lizzy.rs Git - rust.git/commitdiff
Added AsRef implementations for Arc and Rc
authorMarkus Westerlind <marwes91@gmail.com>
Thu, 4 Jun 2015 12:35:04 +0000 (14:35 +0200)
committerMarkus Westerlind <marwes91@gmail.com>
Thu, 4 Jun 2015 12:35:04 +0000 (14:35 +0200)
src/liballoc/arc.rs
src/liballoc/rc.rs

index 593ecc72d50cd00379065dba912c00333742ef39..d12d28335dde606917bd6ab8cccec2389ce40f90 100644 (file)
@@ -332,6 +332,15 @@ fn deref(&self) -> &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>`.
     ///
index 44f4a6a6290c8e04ae12ebd96416921c83a8043a..906a41a4d531410f810da7c1f22902ca37eb23d0 100644 (file)
 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 @@ fn deref(&self) -> &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>`.