vector_tap/
notification.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2/// A component was found that matched the provided pattern
3pub struct Matched {
4    message: String,
5    /// Pattern that raised the notification
6    pub pattern: String,
7}
8
9impl Matched {
10    pub fn new(pattern: String) -> Self {
11        Self {
12            message: format!("[tap] Pattern '{pattern}' successfully matched."),
13            pattern,
14        }
15    }
16}
17
18#[derive(Debug, Clone, PartialEq, Eq)]
19/// There isn't currently a component that matches this pattern
20pub struct NotMatched {
21    message: String,
22    /// Pattern that raised the notification
23    pub pattern: String,
24}
25
26impl NotMatched {
27    pub fn new(pattern: String) -> Self {
28        Self {
29            message: format!(
30                "[tap] Pattern '{pattern}' failed to match: will retry on configuration reload."
31            ),
32            pattern,
33        }
34    }
35}
36
37#[derive(Debug, Clone, PartialEq, Eq)]
38/// The pattern matched source(s) which cannot be tapped for inputs or sink(s)
39/// which cannot be tapped for outputs
40pub struct InvalidMatch {
41    message: String,
42    /// Pattern that raised the notification
43    pattern: String,
44    /// Any invalid matches for the pattern
45    invalid_matches: Vec<String>,
46}
47
48impl InvalidMatch {
49    pub fn new(message: String, pattern: String, invalid_matches: Vec<String>) -> Self {
50        Self {
51            message,
52            pattern,
53            invalid_matches,
54        }
55    }
56}
57
58#[derive(Debug, Clone, PartialEq, Eq)]
59/// A specific kind of notification with additional details
60pub enum Notification {
61    Matched(Matched),
62    NotMatched(NotMatched),
63    InvalidMatch(InvalidMatch),
64}
65
66impl Notification {
67    pub fn as_str(&self) -> &str {
68        match self {
69            Notification::Matched(n) => n.message.as_ref(),
70            Notification::NotMatched(n) => n.message.as_ref(),
71            Notification::InvalidMatch(n) => n.message.as_ref(),
72        }
73    }
74}