optimize log message configuration geneation
This commit is contained in:
parent
9296cc8c80
commit
9b144d234e
@ -1,4 +1,4 @@
|
||||
use std::{collections::{BTreeMap, HashMap}, sync::Mutex};
|
||||
use std::{collections::HashMap, sync::Mutex};
|
||||
use serde::Serialize;
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
use strum_macros::IntoStaticStr;
|
||||
@ -186,20 +186,24 @@ pub enum LogMessage {
|
||||
ConsecutivePumpCountLimit
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct MessageTranslation {
|
||||
msg_type: LogMessage,
|
||||
message: &'static str
|
||||
}
|
||||
|
||||
impl From<&LogMessage> for MessageTranslation {
|
||||
fn from(value: &LogMessage) -> Self {
|
||||
Self { msg_type: value.clone(), message: value.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl LogMessage {
|
||||
pub fn to_log_localisation_config() -> Vec<BTreeMap<&'static str, String>> {
|
||||
pub fn to_log_localisation_config() -> Vec<MessageTranslation> {
|
||||
let mut array = Vec::with_capacity(LogMessage::len());
|
||||
|
||||
for msg_type in LogMessage::iter() {
|
||||
//todo this should be possible without copy?
|
||||
let name = msg_type.name().to_owned();
|
||||
let message: &'static str = msg_type.clone().into();
|
||||
|
||||
|
||||
let mut data = BTreeMap::new();
|
||||
data.insert("msg_type", name);
|
||||
data.insert("message", message.to_owned());
|
||||
array[msg_type.ordinal()] = data;
|
||||
array[msg_type.ordinal()] = (&msg_type).into();
|
||||
}
|
||||
array
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user