| 1 |
|
| 2 |
|
| 3 |
use crate::ids::RoomId; |
| 4 |
use crate::retention::Retention; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 13 |
pub enum RoomState { |
| 14 |
|
| 15 |
Open, |
| 16 |
|
| 17 |
ReadOnly, |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
Closed, |
| 22 |
} |
| 23 |
|
| 24 |
impl RoomState { |
| 25 |
pub fn allows_reads(&self) -> bool { |
| 26 |
matches!(self, Self::Open | Self::ReadOnly) |
| 27 |
} |
| 28 |
|
| 29 |
pub fn allows_writes(&self) -> bool { |
| 30 |
matches!(self, Self::Open) |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 36 |
pub struct Room { |
| 37 |
pub id: RoomId, |
| 38 |
pub state: RoomState, |
| 39 |
pub retention: Retention, |
| 40 |
} |
| 41 |
|
| 42 |
#[cfg(test)] |
| 43 |
mod tests { |
| 44 |
use super::*; |
| 45 |
|
| 46 |
#[test] |
| 47 |
fn closed_rooms_allow_nothing() { |
| 48 |
assert!(!RoomState::Closed.allows_reads()); |
| 49 |
assert!(!RoomState::Closed.allows_writes()); |
| 50 |
} |
| 51 |
|
| 52 |
#[test] |
| 53 |
fn read_only_rooms_read_but_do_not_write() { |
| 54 |
assert!(RoomState::ReadOnly.allows_reads()); |
| 55 |
assert!(!RoomState::ReadOnly.allows_writes()); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn open_rooms_allow_both() { |
| 60 |
assert!(RoomState::Open.allows_reads()); |
| 61 |
assert!(RoomState::Open.allows_writes()); |
| 62 |
} |
| 63 |
} |
| 64 |
|