1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/// Macro for quality matching pattern.
/// This macro provides a zero-cost abstraction for the common pattern of
/// conditional quality matching based on matcher_enabled configuration.
///
/// # Usage
///
/// ```rust
/// use huginn_net::quality_match;
/// # use huginn_net_tcp::output::{OperativeSystem, OSQualityMatched};
/// # use huginn_net_db::{MatchQualityType, Label};
/// # struct Config { matcher_enabled: bool }
/// # struct Matcher;
/// # struct ObservableTcp;
/// # let config = Config { matcher_enabled: true };
/// # let matcher: Option<Matcher> = None;
/// # let observable_tcp = ObservableTcp;
/// let quality = quality_match!(
/// enabled: config.matcher_enabled,
/// matcher: matcher,
/// call: matcher => None::<(Label, String, f32)>,
/// matched: (label, _signature, quality) => OSQualityMatched {
/// os: Some(OperativeSystem::from(&label)),
/// quality: MatchQualityType::Matched(quality),
/// },
/// not_matched: OSQualityMatched {
/// os: None,
/// quality: MatchQualityType::NotMatched,
/// },
/// disabled: OSQualityMatched {
/// os: None,
/// quality: MatchQualityType::Disabled,
/// }
/// );
/// ```
/// Simplified quality matching macro for cases where the matcher call is straightforward.
///
/// This is a convenience macro for the most common use case where you just need
/// to call a single matcher method and handle the three states.
///
/// # Usage
///
/// ```rust
/// use huginn_net::{simple_quality_match, quality_match};
/// # use huginn_net_tcp::output::MTUQualityMatched;
/// # use huginn_net_db::MatchQualityType;
/// # struct Config { matcher_enabled: bool }
/// # struct Matcher;
/// # impl Matcher {
/// # fn matching_by_mtu(&self, _value: &u16) -> Option<(String, String)> { None }
/// # }
/// # struct ObservableMtu { value: u16 }
/// # let config = Config { matcher_enabled: true };
/// # let matcher: Option<Matcher> = None;
/// # let observable_mtu = ObservableMtu { value: 1500 };
/// let quality = simple_quality_match!(
/// enabled: config.matcher_enabled,
/// matcher: matcher,
/// method: matching_by_mtu(&observable_mtu.value),
/// success: (link, _) => MTUQualityMatched {
/// link: Some(link.clone()),
/// quality: MatchQualityType::Matched(1.0),
/// },
/// failure: MTUQualityMatched {
/// link: None,
/// quality: MatchQualityType::NotMatched,
/// },
/// disabled: MTUQualityMatched {
/// link: None,
/// quality: MatchQualityType::Disabled,
/// }
/// );
/// ```
;
}