From 0cca56b2f7e624445fba4e22d2ce6f3866e08703 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sun, 18 Sep 2022 15:58:05 +0100 Subject: [PATCH 1/2] Impl AsRef, Borrow for Ref, RefMut --- library/core/src/cell.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index fb4454c94cb33..4a1be4eb4b9e1 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -1342,6 +1342,22 @@ impl Deref for Ref<'_, T> { } } +#[stable(feature = "borrow_ref", since = "1.65.0")] +impl crate::convert::AsRef for Ref<'_, T> { + #[inline] + fn as_ref(&self) -> &T { + &self + } +} + +#[stable(feature = "borrow_ref", since = "1.65.0")] +impl crate::borrow::Borrow for Ref<'_, T> { + #[inline] + fn borrow(&self) -> &T { + &self + } +} + impl<'b, T: ?Sized> Ref<'b, T> { /// Copies a `Ref`. /// @@ -1733,6 +1749,22 @@ impl DerefMut for RefMut<'_, T> { } } +#[stable(feature = "borrow_ref", since = "1.65.0")] +impl crate::convert::AsRef for RefMut<'_, T> { + #[inline] + fn as_ref(&self) -> &T { + &self + } +} + +#[stable(feature = "borrow_ref", since = "1.65.0")] +impl crate::borrow::Borrow for RefMut<'_, T> { + #[inline] + fn borrow(&self) -> &T { + &self + } +} + #[unstable(feature = "coerce_unsized", issue = "27732")] impl<'b, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized> for RefMut<'b, T> {} From 4754dccffc45d70579ef74599336be8d2bb7493d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 19 Sep 2022 11:53:20 +0100 Subject: [PATCH 2/2] Add AsMut, BorrowMut for RefMut --- library/core/src/cell.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 4a1be4eb4b9e1..137a6fa6191a4 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -1346,7 +1346,7 @@ impl Deref for Ref<'_, T> { impl crate::convert::AsRef for Ref<'_, T> { #[inline] fn as_ref(&self) -> &T { - &self + self } } @@ -1354,7 +1354,7 @@ impl crate::convert::AsRef for Ref<'_, T> { impl crate::borrow::Borrow for Ref<'_, T> { #[inline] fn borrow(&self) -> &T { - &self + self } } @@ -1753,7 +1753,15 @@ impl DerefMut for RefMut<'_, T> { impl crate::convert::AsRef for RefMut<'_, T> { #[inline] fn as_ref(&self) -> &T { - &self + self + } +} + +#[stable(feature = "borrow_ref", since = "1.65.0")] +impl crate::convert::AsMut for RefMut<'_, T> { + #[inline] + fn as_mut(&mut self) -> &mut T { + self } } @@ -1761,7 +1769,15 @@ impl crate::convert::AsRef for RefMut<'_, T> { impl crate::borrow::Borrow for RefMut<'_, T> { #[inline] fn borrow(&self) -> &T { - &self + self + } +} + +#[stable(feature = "borrow_ref", since = "1.65.0")] +impl crate::borrow::BorrowMut for RefMut<'_, T> { + #[inline] + fn borrow_mut(&mut self) -> &mut T { + self } }