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	pub Args:Vec<String>,
17	pub Params:HashMap<String, serde_json::Value>,
18	pub Priority:MessagePriority::Enum,
19}
20
21impl Struct {
22	pub fn new(Command:impl Into<String>) -> Self {
23		Self {
24			Command:Command.into(),
25			Args:Vec::new(),
26			Params:HashMap::new(),
27			Priority:MessagePriority::Enum::Normal,
28		}
29	}
30
31	pub fn WithArg(mut self, Arg:impl Into<String>) -> Self {
32		self.Args.push(Arg.into());
33		self
34	}
35
36	pub fn WithParam(mut self, Key:impl Into<String>, Value:serde_json::Value) -> Self {
37		self.Params.insert(Key.into(), Value);
38		self
39	}
40
41	pub fn WithPriority(mut self, Priority:MessagePriority::Enum) -> Self {
42		self.Priority = Priority;
43		self
44	}
45}