1use std::fmt::Write;
2
3pub trait LineProtocolTag {
5 fn write_key_value_with_comma(&self, buffer: &mut String, key: &str);
7}
8
9impl LineProtocolTag for &str {
11 fn write_key_value_with_comma(&self, buffer: &mut String, key: &str) {
12 if self.contains(char::is_whitespace) {
13 write!(buffer, ",{}={:?}", key, self).unwrap();
14 } else {
15 write!(buffer, ",{}={}", key, self).unwrap();
16 }
17 }
18}
19
20impl LineProtocolTag for str {
22 fn write_key_value_with_comma(&self, buffer: &mut String, key: &str) {
23 (&self).write_key_value_with_comma(buffer, key);
24 }
25}
26
27impl LineProtocolTag for String {
29 fn write_key_value_with_comma(&self, buffer: &mut String, key: &str) {
30 self.as_str().write_key_value_with_comma(buffer, key);
31 }
32}
33
34impl<V> LineProtocolTag for Option<V>
35where
36 V: LineProtocolTag,
37{
38 fn write_key_value_with_comma(&self, buffer: &mut String, key: &str) {
39 if let Some(value) = self {
40 value.write_key_value_with_comma(buffer, key)
41 }
42 }
43}