Made message ids its own structure.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
@@ -12,10 +12,34 @@ use std::{
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct MessageID {
|
||||
data: Uuid,
|
||||
}
|
||||
|
||||
impl MessageID {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: Uuid::new_v4(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod message_ids {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn are_message_ids_unique() {
|
||||
let id1 = MessageID::new();
|
||||
let id2 = MessageID::new();
|
||||
assert!(id1 != id2);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Message {
|
||||
msg_id: Uuid,
|
||||
// document_id: NameType,
|
||||
msg_id: MessageID,
|
||||
action: MsgAction,
|
||||
route: Route,
|
||||
// session: Option<?>
|
||||
@@ -27,13 +51,13 @@ impl Message {
|
||||
A: Into<MsgAction>,
|
||||
{
|
||||
Self {
|
||||
msg_id: Uuid::new_v4(),
|
||||
msg_id: MessageID::new(),
|
||||
action: action.into(),
|
||||
route: Route::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_message_id(&self) -> &Uuid {
|
||||
pub fn get_message_id(&self) -> &MessageID {
|
||||
&self.msg_id
|
||||
}
|
||||
|
||||
@@ -158,11 +182,11 @@ mod messages {
|
||||
|
||||
#[test]
|
||||
fn is_the_message_id_random() {
|
||||
let mut ids: Vec<Uuid> = Vec::new();
|
||||
let mut ids: Vec<MessageID> = Vec::new();
|
||||
for _ in 0..5 {
|
||||
let msg = Message::new(Query::new(Name::english("test")));
|
||||
let id = msg.get_message_id().clone();
|
||||
assert!(!ids.contains(&id), "{:?} containts {}", ids, id);
|
||||
assert!(!ids.contains(&id), "{:?} containts {:?}", ids, id);
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user