babilado_types/
lib.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
4pub enum Event {
5    NewMessage(Message),
6}
7
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
9pub struct Message {
10    pub body: String,
11    pub author: UserId,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
15pub struct User {
16    pub nickname: Nickname,
17    pub tag: Tag,
18    pub id: UserId,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
22pub struct Nickname(String);
23
24impl Nickname {
25    pub fn new(nickname: String) -> Self {
26        Self(nickname)
27    }
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
31pub struct Tag(u16);
32
33impl Tag {
34    pub fn new(tag: u16) -> Self {
35        Self(tag)
36    }
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
40pub struct UserId(u64);
41
42impl UserId {
43    pub fn gen(rng: &mut oorandom::Rand64) -> Self {
44        Self(rng.rand_u64())
45    }
46}