AsRef, AsMut for pool

This commit is contained in:
Andrey Zgarbul 2021-04-02 22:58:08 +03:00
parent e0b3b3a179
commit 618eebfcb9
2 changed files with 38 additions and 0 deletions

View File

@ -439,6 +439,24 @@ unsafe impl<T, S> Sync for Box<T, S> where T: Sync {}
unsafe impl<T> stable_deref_trait::StableDeref for Box<T> {}
impl<A, T> AsRef<[T]> for Box<A>
where
A: AsRef<[T]>,
{
fn as_ref(&self) -> &[T] {
self.deref().as_ref()
}
}
impl<A, T> AsMut<[T]> for Box<A>
where
A: AsMut<[T]>,
{
fn as_mut(&mut self) -> &mut [T] {
self.deref_mut().as_mut()
}
}
impl<T> Deref for Box<T> {
type Target = T;

View File

@ -244,6 +244,26 @@ where
{
}
impl<P, T> AsRef<[T]> for Box<P>
where
P: Pool,
P::Data: AsRef<[T]>,
{
fn as_ref(&self) -> &[T] {
self.deref().as_ref()
}
}
impl<P, T> AsMut<[T]> for Box<P>
where
P: Pool,
P::Data: AsMut<[T]>,
{
fn as_mut(&mut self) -> &mut [T] {
self.deref_mut().as_mut()
}
}
impl<P> PartialEq for Box<P>
where
P: Pool,