created a event result builder

This commit is contained in:
michael-bailey 2022-04-21 08:20:22 +01:00
parent fc12e8f608
commit 04aef9cd9f
1 changed files with 42 additions and 0 deletions

View File

@ -1,3 +1,4 @@
use futures::channel::oneshot::Sender;
use std::collections::HashMap;
pub enum EventResultType {
@ -11,3 +12,44 @@ pub struct EventResult {
code: EventResultType,
args: HashMap<String, String>,
}
impl EventResult {
pub fn create(result_type: EventResultType) -> EventResultBuilder {
EventResultBuilder::new(result_type)
}
}
pub struct EventResultBuilder {
code: EventResultType,
args: HashMap<String, String>,
}
impl EventResultBuilder {
pub(self) fn new(result_type: EventResultType) -> Self {
Self {
code: result_type,
args: HashMap::default(),
}
}
pub fn add_arg(mut self, key: String, value: String) -> Self {
self.args.insert(key, value);
self
}
pub fn build(self) -> EventResult {
EventResult {
code: self.code,
args: self.args,
}
}
pub fn send(self, sender: Sender<EventResult>) {
sender
.send(EventResult {
code: self.code,
args: self.args,
})
.ok();
}
}