Skip to main content

GuardedTarget

Trait GuardedTarget 

Source
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))

Required Associated Types§

Source

type Target

Dereferencing target of the read and write guards.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> GuardedTarget for &RwLock<T>

Source§

impl<T> GuardedTarget for &mut RwLock<T>

Source§

impl<T> GuardedTarget for RwLock<T>

Implementors§