impl Borrow
and AsRef
for CowArc
(#11616)
# Objective - Allow `HashMap<Cow<'_, T>, _>` to use `&T` as key for `HashMap::get` - Makes `CowArc` more like `Cow` ## Solution Implements `Borrow<T>` and `AsRef<T>` for `CowArc<T>`.
This commit is contained in:
parent
6b40b6749e
commit
4b7ef44bb4
@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
borrow::Borrow,
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
@ -37,6 +38,20 @@ impl<'a, T: ?Sized> Deref for CowArc<'a, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, T: ?Sized> Borrow<T> for CowArc<'a, T> {
|
||||||
|
#[inline]
|
||||||
|
fn borrow(&self) -> &T {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: ?Sized> AsRef<T> for CowArc<'a, T> {
|
||||||
|
#[inline]
|
||||||
|
fn as_ref(&self) -> &T {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, T: ?Sized> CowArc<'a, T>
|
impl<'a, T: ?Sized> CowArc<'a, T>
|
||||||
where
|
where
|
||||||
&'a T: Into<Arc<T>>,
|
&'a T: Into<Arc<T>>,
|
||||||
|
Loading…
Reference in New Issue
Block a user