Skip to main content

Mountain/IPC/Common/MessageType/
IPCCommand.rs

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