Expand description
§Line Protocol
This crate offers helper types and macros to build line protocol strings.
§Usage
To generate line protocols, your type must implement LineProtocol trait.
You can also implement LineProtocolTag for custom types to be used as tags.
§Automatic Implementation
You can easily derive LineProtocol and LineProtocolTag from the types.
use std::time::SystemTime;
use line_protocol::{LineProtocolTag, LineProtocol};
#[derive(LineProtocolTag)]
#[line_protocol(case = "kebab")]
enum Room {
Kitchen,
LivingRoom,
Bathroom,
}
#[derive(LineProtocol)]
#[line_protocol(measurement = "environment")]
struct EnvironmentMeasurement {
#[line_protocol(tag)]
room: Room,
#[line_protocol(field)]
temperature: f32,
#[line_protocol(field)]
humidity: f32,
#[line_protocol(timestamp)]
timestamp: SystemTime,
}§Manual Implementation
For more complex situations, you may implement the trait using the builder syntax.
use std::time::SystemTime;
use line_protocol::{LineProtocol, LineProtocolTag, LineProtocolBuilder};
struct EnvironmentMeasurement {
room: String,
temperature: f32,
humidity: f32,
timestamp: SystemTime,
}
impl LineProtocol for EnvironmentMeasurement {
fn to_line_protocol(&self) -> Option<String> {
LineProtocolBuilder::default()
.measurement("environment")
.tag("room", &self.room)
.field("temperature", &self.temperature)
.field("humidity", &self.humidity)
.timestamp(&self.timestamp)
.build()
}
}§Helper Traits
Both automatic and manual implementations shown above require that your type implements helper traits.
- If your field is a line protocol tag, it needs to implement
LineProtocolTag. - If your field is a line protocol field, it needs to implement
LineProtocolField. - If your field is a line protocol timestamp, it needs to implement
LineProtocolTimestamp.
Structs§
- Line
Protocol Builder - Helper type for building a line protocol string.
- Line
Protocol Builder Fields - Helper type for building a line protocol string (fields insertion).
- Line
Protocol Builder Tags - Helper type for building a line protocol string (tags insertion).
- Line
Protocol Builder Timestamp - Helper type for building a line protocol string (timestamp insertion).
Traits§
- Line
Protocol - Defines a type that may be converted to a line protocol string.
- Line
Protocol Field - Defines a type that can be written as a line protocol field.
- Line
Protocol Tag - Defines a type that can be written as a line protocol tag.
- Line
Protocol Timestamp - Defines a type that can be written as a line protocol timestamp.
Derive Macros§
- Line
Protocol - Derive macro for
LineProtocol. - Line
Protocol Tag - Derive macro for
LineProtocolTag.