pubsub_bus/event.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
// *************************************************************************
//
// Copyright (c) 2025 Andrei Gramakov. All rights reserved.
//
// This file is licensed under the terms of the MIT license.
// For a copy, see: https://opensource.org/licenses/MIT
//
// site: https://agramakov.me
// e-mail: mail@agramakov.me
//
// *************************************************************************
#[cfg(test)]
mod tests;
pub struct Event<ContentType> {
id: u64,
source_id: u64,
content: ContentType,
}
impl<ContentType> Event<ContentType> {
pub fn new(content: ContentType) -> Self {
Event {
id: 0,
source_id: 0,
content,
}
}
pub fn set_header(&mut self, id: u64, source_id: u64) {
self.id = id;
self.source_id = source_id;
}
pub fn get_id(&self) -> u64 {
self.id
}
pub fn get_source_id(&self) -> u64 {
self.source_id
}
pub fn get_content(&self) -> &ContentType {
&self.content
}
pub fn get_mut_content(&mut self) -> &mut ContentType {
&mut self.content
}
}
pub trait IntoEvent<ContentType> {
fn into_event(self) -> Event<ContentType>;
}
impl<ContentType> IntoEvent<ContentType> for ContentType {
fn into_event(self) -> Event<ContentType> {
Event::new(self)
}
}