Skip to content

Commit

Permalink
impl Borrow and AsRef for CowArc (bevyengine#11616)
Browse files Browse the repository at this point in the history
# 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>`.
  • Loading branch information
tguichaoua authored and tjamaan committed Feb 6, 2024
1 parent 1db333e commit b9293d5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/bevy_utils/src/cow_arc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
borrow::Borrow,
fmt::{Debug, Display},
hash::Hash,
ops::Deref,
Expand Down Expand Up @@ -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>
where
&'a T: Into<Arc<T>>,
Expand Down

0 comments on commit b9293d5

Please sign in to comment.