line_protocol/lib.rs
1#![doc = include_str!("../README.md")]
2
3mod builder;
4mod field;
5mod tag;
6mod timestamp;
7
8pub use crate::builder::*;
9pub use crate::field::*;
10pub use crate::tag::*;
11pub use crate::timestamp::*;
12
13/// Defines a type that may be converted to a line protocol string.
14pub trait LineProtocol {
15 fn to_line_protocol(&self) -> Option<String>;
16}
17
18/// Derive macro for [`LineProtocol`].
19///
20/// # Named Struct
21///
22/// This macro supports named structs.
23///
24/// * `#[line_protocol(measurement = "...")]` must be defined once on the type.
25/// * `#[line_protocol(tag)]` may be used to define tags.
26/// * `#[line_protocol(field)]` must be used at least once to define a field.
27/// * `#[line_protocol(timestamp)]` may be used once to define the timestamp.
28/// * `#[line_protocol(rename = "...")]` to rename the tags/fields.
29///
30/// ## Example
31///
32/// ```
33/// use std::time::SystemTime;
34/// use line_protocol::LineProtocol;
35///
36/// #[derive(LineProtocol)]
37/// #[line_protocol(measurement = "power")]
38/// struct PowerMeasurement {
39/// #[line_protocol(tag)]
40/// room: String,
41/// #[line_protocol(tag)]
42/// outlet: String,
43/// #[line_protocol(field)]
44/// current: f32,
45/// #[line_protocol(field)]
46/// voltage: f32,
47/// #[line_protocol(timestamp)]
48/// timestamp: SystemTime,
49/// }
50/// ```
51///
52/// # Unnamed Struct
53///
54/// This macro supports unnamed structs, although it is not recommended.
55///
56/// * It works almost the same way as for named structs.
57/// * `#[line_protocol(rename = "...")]` must be used on all tags/fields.
58///
59/// ## Example
60///
61/// ```
62/// use std::time::SystemTime;
63/// use line_protocol::LineProtocol;
64///
65/// #[derive(LineProtocol)]
66/// #[line_protocol(measurement = "temperature")]
67/// struct TemperatureMeasurement(
68/// #[line_protocol(tag, rename = "room")]
69/// String,
70/// #[line_protocol(field, rename = "temperature")]
71/// f32,
72/// #[line_protocol(timestamp)]
73/// SystemTime,
74/// );
75/// ```
76///
77/// # Notes
78///
79/// If you're using a `String` or a `&str` as a tag, it will get double-quoted if they string contains spaces.
80pub use line_protocol_derive::LineProtocol;
81
82/// Derive macro for [`LineProtocolTag`].
83///
84/// # Enum Type
85///
86/// This macro supports enum type. It may have fields, but they are ignored.
87///
88/// * `#[line_protocol(case = "...")]` may be used to automatically rename the all variants.
89/// * The possible choices is currently `kebab` (default), `pascal` or `snake`.
90/// * `#[line_protocol(rename = "...")]` may be used to rename individual variants.
91///
92/// ## Example
93///
94/// ```
95/// use line_protocol::LineProtocolTag;
96///
97/// #[derive(LineProtocolTag)]
98/// #[line_protocol(case = "kebab")]
99/// enum Station {
100/// PowerStation1,
101/// PowerStation2,
102/// PowerStation3,
103/// #[line_protocol(rename = "thermal-station-1")]
104/// ThermalChamber1,
105/// #[line_protocol(rename = "thermal-station-2")]
106/// ThermalChamber2,
107/// }
108/// ```
109pub use line_protocol_derive::LineProtocolTag;