rlqt_lib/rel_db/
presets.rs1use crate::entry_metadata::labels::LogEntryLabels;
15use crate::rel_db::node_log_entry::QueryContext;
16use serde::{Deserialize, Serialize};
17use std::fmt;
18use std::str::FromStr;
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21#[serde(rename_all = "snake_case")]
22pub enum QueryPreset {
23 ErrorsOrCrashes,
24}
25
26impl fmt::Display for QueryPreset {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 QueryPreset::ErrorsOrCrashes => write!(f, "errors_or_crashes"),
30 }
31 }
32}
33
34impl FromStr for QueryPreset {
35 type Err = String;
36
37 fn from_str(s: &str) -> Result<Self, Self::Err> {
38 match s {
39 "errors_or_crashes" => Ok(QueryPreset::ErrorsOrCrashes),
40 _ => Err(format!("Unknown preset: {}", s)),
41 }
42 }
43}
44
45impl QueryPreset {
46 pub fn severity(&self) -> Option<&'static str> {
47 match self {
48 QueryPreset::ErrorsOrCrashes => Some("error"),
49 }
50 }
51
52 pub fn labels(&self) -> LogEntryLabels {
53 match self {
54 QueryPreset::ErrorsOrCrashes => {
55 LogEntryLabels::ERL_PROCESS_CRASH | LogEntryLabels::EXCEPTIONS
56 }
57 }
58 }
59}
60
61impl From<QueryPreset> for QueryContext {
62 fn from(preset: QueryPreset) -> Self {
63 QueryContext {
64 preset: Some(preset),
65 ..Default::default()
66 }
67 }
68}