read_write_api/wrappers.rs
1#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash)]
2/// [`ReadApi`](crate::ReadApi) wrapper for constant references.
3///
4/// # Example
5///
6/// ```rust
7/// use read_write_api::{ReadApi, ReadApiWrapper};
8/// use parking_lot::RwLock;
9///
10/// fn read<T: ReadApi>(x: &T) -> T::ReadGuard<'_> {
11/// x.read()
12/// }
13///
14/// let _ = read(&ReadApiWrapper(&1));
15/// let _ = read(&RwLock::new(2));
16/// ```
17pub struct ReadApiWrapper<'a, T: ?Sized>(
18 /// Wrapped reference.
19 pub &'a T
20);
21
22#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
23/// [`RwApi`](crate::RwApi) wrapper for mutable references.
24///
25/// # Example
26///
27/// See the [`RwApi`](crate::RwApi) docs for usage examples.
28pub struct RwApiWrapper<'a, T: ?Sized>(
29 /// Wrapped reference.
30 pub &'a mut T
31);
32
33#[derive(Default, Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash)]
34/// [`RwApi`](crate::RwApi) owning wrapper for solitary objects.
35///
36/// # Example
37///
38/// See the [`RwApi`](crate::RwApi) docs for usage examples.
39pub struct RwApiWrapperOwned<T>(
40 /// Wrapped owned object.
41 pub T
42);