|
1 |
| -pub trait Access {} |
2 |
| - |
3 |
| -/// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`]. |
4 |
| -pub trait Readable: UnsafelyReadable {} |
5 |
| - |
6 |
| -/// Helper trait that is implemented by [`ReadWrite`] and [`WriteOnly`]. |
7 |
| -pub trait Writable: UnsafelyWritable {} |
8 |
| - |
9 |
| -pub trait UnsafelyReadable {} |
10 |
| - |
11 |
| -pub trait UnsafelyWritable {} |
12 |
| - |
13 |
| -/// Zero-sized marker type for allowing both read and write access. |
14 |
| -#[derive(Debug, Copy, Clone)] |
15 |
| -pub struct ReadWrite; |
16 |
| -impl Access for ReadWrite {} |
17 |
| -impl Readable for ReadWrite {} |
18 |
| -impl UnsafelyReadable for ReadWrite {} |
19 |
| -impl Writable for ReadWrite {} |
20 |
| -impl UnsafelyWritable for ReadWrite {} |
| 1 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 2 | +pub struct NoAccess; |
21 | 3 |
|
22 |
| -/// Zero-sized marker type for allowing only read access. |
23 |
| -#[derive(Debug, Copy, Clone)] |
24 |
| -pub struct ReadOnly; |
| 4 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 5 | +pub struct UnsafeAccess; |
25 | 6 |
|
26 |
| -impl Access for ReadOnly {} |
27 |
| -impl Readable for ReadOnly {} |
28 |
| -impl UnsafelyReadable for ReadOnly {} |
| 7 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 8 | +pub struct SafeAccess; |
29 | 9 |
|
30 |
| -/// Zero-sized marker type for allowing only write access. |
31 |
| -#[derive(Debug, Copy, Clone)] |
32 |
| -pub struct WriteOnly; |
| 10 | +pub trait Unsafe {} |
| 11 | +pub trait Safe: Unsafe {} |
33 | 12 |
|
34 |
| -impl Access for WriteOnly {} |
35 |
| -impl Writable for WriteOnly {} |
36 |
| -impl UnsafelyWritable for WriteOnly {} |
| 13 | +impl Unsafe for UnsafeAccess {} |
| 14 | +impl Unsafe for SafeAccess {} |
| 15 | +impl Safe for SafeAccess {} |
37 | 16 |
|
38 |
| -#[derive(Clone, Copy, PartialEq, Eq)] |
39 |
| -pub struct Custom<R, W> { |
| 17 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 18 | +pub struct Access<R, W> { |
40 | 19 | pub read: R,
|
41 | 20 | pub write: W,
|
42 | 21 | }
|
43 | 22 |
|
44 |
| -#[derive(Clone, Copy, PartialEq, Eq)] |
45 |
| -pub struct NoAccess; |
46 |
| -#[derive(Clone, Copy, PartialEq, Eq)] |
47 |
| -pub struct SafeAccess; |
48 |
| -#[derive(Clone, Copy, PartialEq, Eq)] |
49 |
| -pub struct UnsafeAccess; |
| 23 | +impl Access<SafeAccess, NoAccess> { |
| 24 | + pub const fn read_only() -> ReadOnly { |
| 25 | + Access { |
| 26 | + read: SafeAccess, |
| 27 | + write: NoAccess, |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + pub fn write_only() -> WriteOnly { |
| 32 | + Access { |
| 33 | + read: NoAccess, |
| 34 | + write: SafeAccess, |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + pub fn read_write() -> ReadWrite { |
| 39 | + Access { |
| 40 | + read: SafeAccess, |
| 41 | + write: SafeAccess, |
| 42 | + } |
| 43 | + } |
| 44 | +} |
50 | 45 |
|
51 |
| -impl<W> Readable for Custom<SafeAccess, W> {} |
52 |
| -impl<W> UnsafelyReadable for Custom<SafeAccess, W> {} |
53 |
| -impl<W> UnsafelyReadable for Custom<UnsafeAccess, W> {} |
54 |
| -impl<R> Writable for Custom<R, SafeAccess> {} |
55 |
| -impl<R> UnsafelyWritable for Custom<R, SafeAccess> {} |
56 |
| -impl<R> UnsafelyWritable for Custom<R, UnsafeAccess> {} |
| 46 | +pub type ReadOnly = Access<SafeAccess, NoAccess>; |
| 47 | +pub type WriteOnly = Access<NoAccess, SafeAccess>; |
| 48 | +pub type ReadWrite = Access<SafeAccess, SafeAccess>; |
0 commit comments