Skip to content

Commit

Permalink
Make types like Box<dyn DynAccess> implement Access
Browse files Browse the repository at this point in the history
by generalizing the P: Deref-implementation to ?Sized,
and implementing Access for some `dyn DynAccess` trait object types.

Not yet documented or polished, this commit's main purpose is to allow CI testing.
  • Loading branch information
steffahn committed Jul 5, 2022
1 parent f7f192d commit a113002
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/access.rs
Expand Up @@ -112,13 +112,53 @@ pub trait Access<T> {
fn load(&self) -> Self::Guard;
}

impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
impl<T, A: Access<T> + ?Sized, P: Deref<Target = A>> Access<T> for P {
type Guard = A::Guard;
fn load(&self) -> Self::Guard {
self.deref().load()
}
}

impl<T> Access<T> for dyn DynAccess<T> + '_ {
type Guard = DynGuard<T>;

fn load(&self) -> Self::Guard {
self.load()
}
}

impl<T> Access<T> for dyn DynAccess<T> + '_ + Send {
type Guard = DynGuard<T>;

fn load(&self) -> Self::Guard {
self.load()
}
}

impl<T> Access<T> for dyn DynAccess<T> + '_ + Sync + Send {
type Guard = DynGuard<T>;

fn load(&self) -> Self::Guard {
self.load()
}
}

// Should probably be moved to a more appropriate place / perhaps more extensively tested / etc
#[cfg(test)]
mod test {
use super::*;
fn _expect_access<T>(_: impl Access<T>) {}
fn _test1<T>(x: Box<dyn DynAccess<T> + '_>) {
_expect_access(x)
}
fn _test2<T>(x: Box<dyn DynAccess<T> + '_ + Send>) {
_expect_access(x)
}
fn _test3<T>(x: Box<dyn DynAccess<T> + '_ + Send + Sync>) {
_expect_access(x)
}
}

impl<T: RefCnt, S: Strategy<T>> Access<T> for ArcSwapAny<T, S> {
type Guard = Guard<T, S>;

Expand Down

0 comments on commit a113002

Please sign in to comment.