Skip to main content

Mountain/IPC/Common/MessageType/
IPCCommand.rs

1
2//! IPC command request: command name + positional `Args` + named
3//! `Params` map + a priority. Built through `new` and the `WithArg` /
4//! `WithParam` / `WithPriority` builder shims.
5
6use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9
10use crate::IPC::Common::MessageType::MessagePriority;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct Struct {
14	pub Command:String,
15
16	pub Args:Vec<String>,
17
18	pub Params:HashMap<String, serde_json::Value>,
19
20	pub Priority:MessagePriority::Enum,
21}
22
23impl Struct {
24	pub fn new(Command:impl Into<String>) -> Self {
25		Self {
26			Command:Command.into(),
27
28			Args:Vec::new(),
29
30			Params:HashMap::new(),
31
32			Priority:MessagePriority::Enum::Normal,
33		}
34	}
35
36	pub fn WithArg(mut self, Arg:impl Into<String>) -> Self {
37		self.Args.push(Arg.into());
38
39		self
40	}
41
42	pub fn WithParam(mut self, Key:impl Into<String>, Value:serde_json::Value) -> Self {
43		self.Params.insert(Key.into(), Value);
44
45		self
46	}
47
48	pub fn WithPriority(mut self, Priority:MessagePriority::Enum) -> Self {
49		self.Priority = Priority;
50
51		self
52	}
53}