config: store and parse 'filter' as regex

This commit is contained in:
Bruno BELANYI 2021-04-10 02:01:19 +02:00 committed by Antoine Martin
parent 54f67887aa
commit ad420dc874
3 changed files with 38 additions and 2 deletions

View file

@ -1,4 +1,5 @@
use matrix_sdk::identifiers::RoomId;
use regex::Regex;
use serde::de::{self, MapAccess, Visitor};
use serde::{Deserialize, Deserializer};
use std::fmt;
@ -27,15 +28,24 @@ pub struct Config {
}
/// Holds a single unit's configuration.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize)]
#[serde(from = "SerializedUnit")]
pub struct Unit {
/// Can be serialized from a string only instead of a map.
pub name: String,
/// Regex to filter each line read from the unit's logs.
pub filter: Option<String>, // FIXME: regex
#[serde(with = "serde_regex")]
pub filter: Option<Regex>,
}
impl PartialEq for Unit {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
impl Eq for Unit {}
#[derive(Debug, Deserialize)]
#[serde(transparent)]
struct SerializedUnit(#[serde(deserialize_with = "unit_name_or_struct")] Unit);