use crate::model::JobAction; #[derive(Debug, Clone, Copy, PartialEq)] pub enum Subject { Action(JobAction), StopManager, Empty, } impl Subject { pub fn new_action(action: JobAction) -> Self { Subject::Action(action) } } #[derive(Debug)] pub struct Body { id: u32, } impl Body { fn new(id: u32) -> Self { Self { id: id } } fn get_id(&self) -> u32 { self.id } } pub struct Message { subject: Subject, body: Option, } impl Message { pub fn new(id: u32, subject: Subject) -> Self { Self { subject: subject, body: Some(Body::new(id)), } } pub fn empty() -> Self { Self { subject: Subject::Empty, body: None, } } pub fn stop() -> Self { Self { subject: Subject::StopManager, body: None, } } pub fn get_subject(&self) -> Subject { self.subject } pub fn get_body_id(&self) -> Option { match self.body { Some(ref b) => Some(b.get_id()), None => None, } } }