rinfluxdb_lineprotocol/
tag_value.rs1#[derive(Clone, Debug, PartialEq, Eq, Hash)]
9pub struct TagValue(String);
10
11impl TagValue {
12 pub fn escape_to_line_protocol(&self) -> String {
16 self.0
17 .replace(" ", "\\ ")
18 .replace(",", "\\,")
19 .replace("=", "\\=")
20 }
21}
22
23impl From<&str> for TagValue {
24 fn from(s: &str) -> Self {
25 Self(s.to_string())
26 }
27}
28
29impl From<String> for TagValue {
30 fn from(s: String) -> Self {
31 Self(s)
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38 use quickcheck::{Arbitrary, Gen};
39
40 impl Arbitrary for TagValue {
41 fn arbitrary(g: &mut Gen) -> Self {
42 let value = String::arbitrary(g);
43 TagValue(value)
44 }
45 }
46}