dbus_message_parser/match_rule/
encode.rs

1use super::MatchRule;
2use std::fmt::{Display, Formatter, Result as FmtResult};
3
4impl Display for MatchRule {
5    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
6        match self {
7            MatchRule::Type(r#type) => write!(f, "type={}", r#type),
8            MatchRule::Sender(sender) => write!(f, "sender={}", sender),
9            MatchRule::Interface(interface) => write!(f, "interface={}", interface),
10            MatchRule::Member(member) => write!(f, "member={}", member),
11            MatchRule::Path(path) => write!(f, "path={}", path),
12            MatchRule::PathNamespace(path_namespace) => {
13                write!(f, "path_namespace={}", path_namespace)
14            }
15            MatchRule::Destination(destination) => write!(f, "destination={}", destination),
16            MatchRule::Arg(arg) => write!(f, "{}={}", arg.get_key(), arg),
17            MatchRule::ArgPath(arg_path) => write!(f, "{}={}", arg_path.get_key(), arg_path),
18            MatchRule::Arg0Namespace(arg0_namespace) => {
19                write!(f, "arg0namespace={}", arg0_namespace)
20            }
21            MatchRule::Eavesdrop(eavesdrop) => {
22                write!(f, "eavesdrop=")?;
23                if *eavesdrop {
24                    write!(f, "true")
25                } else {
26                    write!(f, "false")
27                }
28            }
29        }
30    }
31}
32
33impl MatchRule {
34    pub fn encode(match_rules: &[MatchRule]) -> String {
35        let mut iter = match_rules.iter();
36        if let Some(match_rule) = iter.next() {
37            let mut result = match_rule.to_string();
38            for match_rule in iter {
39                result.push(',');
40                result.push_str(match_rule.to_string().as_str());
41            }
42            result
43        } else {
44            String::new()
45        }
46    }
47}