created a event result builder
This commit is contained in:
parent
fc12e8f608
commit
04aef9cd9f
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue