pub trait GuardedTarget {
type Target;
}
Expand description
Provides a single dereferencing target type for
the ReadApi
, WriteApi
and RwApi
traits.
§Example
use read_write_api::{
DowngradableWriteApi,
GuardedTarget,
ReadApi,
RwApi,
UpgradableReadApi,
WriteApi
};
struct A(u64);
impl GuardedTarget for A {
type Target = u64;
}
impl ReadApi for A
{
type ReadGuard<'a> = &'a u64
where Self: 'a;
fn read(&self) -> Self::ReadGuard<'_> {
&self.0
}
}
impl WriteApi for A
{
type WriteGuard<'a> = &'a mut u64
where Self: 'a;
fn write(&mut self) -> Self::WriteGuard<'_> {
&mut self.0
}
}
impl UpgradableReadApi for A
{
type UpgradableReadGuard<'a> = &'a mut u64
where Self: 'a;
fn upgradable_read(&mut self) -> Self::UpgradableReadGuard<'_> {
&mut self.0
}
}
impl DowngradableWriteApi for A
{
type DowngradableWriteGuard<'a> = &'a mut u64
where Self: 'a;
fn downgradable_write(&mut self) -> Self::DowngradableWriteGuard<'_> {
&mut self.0
}
}
fn accept_read_write(_: impl RwApi<Target=u64>) {}
accept_read_write(A(1))