From 7f3ae0aa26d24100379ae0f3eef29916a32f4e79 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Thu, 4 Jun 2015 14:35:04 +0200 Subject: [PATCH] Added AsRef implementations for Arc and Rc --- src/liballoc/arc.rs | 9 +++++++++ src/liballoc/rc.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 593ecc72d50cd..d12d28335dde6 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -332,6 +332,15 @@ impl Deref for Arc { } } +#[stable(feature = "rc_arc_as_ref", since = "1.2.0")] +impl AsRef for Arc { + + #[inline] + fn as_ref(&self) -> &T { + &self.inner().data + } +} + impl Arc { /// Make a mutable reference from the given `Arc`. /// diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 44f4a6a6290c8..906a41a4d5314 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 Deref for Rc { } } +#[stable(feature = "rc_arc_as_ref", since = "1.2.0")] +impl AsRef for Rc { + + #[inline(always)] + fn as_ref(&self) -> &T { + &self.inner().value + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Drop for Rc { /// Drops the `Rc`.