Skip to content

Commit 7f3ae0a

Browse files
committed
Added AsRef implementations for Arc and Rc
1 parent 80d08a3 commit 7f3ae0a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/liballoc/arc.rs

+9
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ impl<T: ?Sized> Deref for Arc<T> {
332332
}
333333
}
334334

335+
#[stable(feature = "rc_arc_as_ref", since = "1.2.0")]
336+
impl<T: ?Sized> AsRef<T> for Arc<T> {
337+
338+
#[inline]
339+
fn as_ref(&self) -> &T {
340+
&self.inner().data
341+
}
342+
}
343+
335344
impl<T: Clone> Arc<T> {
336345
/// Make a mutable reference from the given `Arc<T>`.
337346
///

src/liballoc/rc.rs

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ use std::boxed;
156156
use core::cell::Cell;
157157
use core::clone::Clone;
158158
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
159+
use core::convert::AsRef;
159160
use core::default::Default;
160161
use core::fmt;
161162
use core::hash::{Hasher, Hash};
@@ -379,6 +380,15 @@ impl<T: ?Sized> Deref for Rc<T> {
379380
}
380381
}
381382

383+
#[stable(feature = "rc_arc_as_ref", since = "1.2.0")]
384+
impl<T: ?Sized> AsRef<T> for Rc<T> {
385+
386+
#[inline(always)]
387+
fn as_ref(&self) -> &T {
388+
&self.inner().value
389+
}
390+
}
391+
382392
#[stable(feature = "rust1", since = "1.0.0")]
383393
impl<T: ?Sized> Drop for Rc<T> {
384394
/// Drops the `Rc<T>`.

0 commit comments

Comments
 (0)