pub struct LineProtocol {
pub measurement: Measurement,
pub tags: Option<HashMap<TagKey, TagValue>>,
pub fields: HashMap<FieldKey, FieldValue>,
pub timestamp: Option<i64>,
}Fields§
§measurement: MeasurementThe data point measurement name
The data point tag set
fields: HashMap<FieldKey, FieldValue>The data point field set
timestamp: Option<i64>To ensure a data point includes the time a metric is observed (not received by InfluxDB), include a timestamp if not defined
By default the timestamp is defined in nanoseconds. If you are using any other form of precision it needs to be defined when making the insert request
Implementations§
Source§impl LineProtocol
impl LineProtocol
Sourcepub fn new<T>(measurement: T) -> Selfwhere
T: Into<Measurement>,
pub fn new<T>(measurement: T) -> Selfwhere
T: Into<Measurement>,
Create a new LineProtocol for building a single data point
§Args
measurement- A valid measurement name
Sourcepub fn measurement<T>(self, measurement: T) -> Selfwhere
T: Into<Measurement>,
pub fn measurement<T>(self, measurement: T) -> Selfwhere
T: Into<Measurement>,
Sourcepub fn measurement_ref<T>(&mut self, measurement: T)where
T: Into<Measurement>,
pub fn measurement_ref<T>(&mut self, measurement: T)where
T: Into<Measurement>,
Sourcepub fn add_tag<K, V>(self, key: K, value: V) -> Self
pub fn add_tag<K, V>(self, key: K, value: V) -> Self
Add or update a tag key-value pair to the data point
This function is useful if you want to follow a builder pattern
§Example
let line_protocol = LineProtocol::new("measurement").add_tag("key", "value");§Args
Sourcepub fn add_tag_ref<K, V>(&mut self, key: K, value: V)
pub fn add_tag_ref<K, V>(&mut self, key: K, value: V)
Add or update a tag key-value pair to the data point
This function is useful if you want to build a data point dynamically
§Example
let line_protocol = LineProtocol::new("measurement");
for (key, value) in tags {
line_protocol.add_tag_ref(key, value);
}§Args
Sourcepub fn delete_tag<K>(self, key: K) -> Self
pub fn delete_tag<K>(self, key: K) -> Self
Sourcepub fn delete_tag_ref<K>(&mut self, key: K)
pub fn delete_tag_ref<K>(&mut self, key: K)
Sourcepub fn add_field<K, V>(self, key: K, value: V) -> Self
pub fn add_field<K, V>(self, key: K, value: V) -> Self
Add or update a field key-value pair to the data point
This function is useful if you want to follow a builder pattern
§Example
let line_protocol = LineProtocol::new("measurement").add_field("key", "value");§Args
Sourcepub fn add_field_ref<K, V>(&mut self, key: K, value: V)
pub fn add_field_ref<K, V>(&mut self, key: K, value: V)
Add or update a field key-value pair to the data point
This function is useful if you want to build a data point dynamically
§Example
let line_protocol = LineProtocol::new("measurement");
for (key, value) in fields {
line_protocol.add_field_ref(key, value);
}§Args
Sourcepub fn delete_field<K>(self, key: K) -> Self
pub fn delete_field<K>(self, key: K) -> Self
Sourcepub fn delete_field_ref<K>(&mut self, key: K)
pub fn delete_field_ref<K>(&mut self, key: K)
Sourcepub fn with_timestamp<T>(self, timestamp: T) -> Self
pub fn with_timestamp<T>(self, timestamp: T) -> Self
Set the timestamp for the data point
It is recommend to set a timestamp. By default InfluxDB v2 expects the timestamp to be in nanosecond precision. If you are using any other form of precision it needs to be explicitly set when making the query
§Example
let line_protocol = LineProtocol::new("measurement");
.with_timestamp(1729270461612452700i64);§Args
timestamp- A unix timestamp
Sourcepub fn with_timestamp_ref<T>(&mut self, timestamp: T)
pub fn with_timestamp_ref<T>(&mut self, timestamp: T)
Set the timestamp for the data point
It is recommend to set a timestamp. By default InfluxDB v2 expects the timestamp to be in nanosecond precision. If you are using any other form of precision it needs to be explicitly set when making the query
§Example
let line_protocol = LineProtocol::new("measurement");
line_protocol.with_timestamp_ref(1729270461612452700i64);§Args
timestamp- A unix timestamp
Sourcepub fn delete_timestamp(self) -> Self
pub fn delete_timestamp(self) -> Self
Delete the set timestamp
§Example
let mut line_protocol = LineProtocol::new("measurement")
.add_field("key", "value")
.with_timestamp_ref(1729270461612452700i64);
line_protocol = line_protocol.delete_timestamp();Sourcepub fn delete_timestamp_ref(&mut self)
pub fn delete_timestamp_ref(&mut self)
Delete the set timestamp
§Example
let mut line_protocol = LineProtocol::new("measurement")
.add_field("key", "value")
.with_timestamp_ref(1729270461612452700i64);
line_protocol.delete_timestamp();Sourcepub fn build(&self) -> Result<String, LineProtocolError>
pub fn build(&self) -> Result<String, LineProtocolError>
Builds an InfluxDB v2 data point using the previously defined measurement name, optional tags, fields, and an optional timestamp
In addition validation checks are performed on the individual parts
Source§impl LineProtocol
impl LineProtocol
Sourcepub fn parse_line(line: &str) -> Result<Self, LineProtocolError>
pub fn parse_line(line: &str) -> Result<Self, LineProtocolError>
Parse a single line protocol line into the LineProtocol struct
Allows for modifying the line protocol by adding or removing fields/tags and rebuilding
§Example
let line = "measurement,tag=value field=true 1729270461612452700"
let parsed_line = LineProtocol::parse_line(line).unwrap();
parsed_line.delete_tag("tag");
parsed_line.add_field("field2", "hello");
parsed_line.with_timestamp(1729270461612452800i64)
let line = parsed_line.build().unwrap();
// Output: measurement field=true,field2="hello" 1729270461612452800§Args
line- A InfluxDB line protocol line
Sourcepub fn parse_vec(lines: Vec<&str>) -> Result<Vec<Self>, LineProtocolError>
pub fn parse_vec(lines: Vec<&str>) -> Result<Vec<Self>, LineProtocolError>
Parse a vector of lines
Empty lines and comment lines are silently ignored
§Example
let lines = vec![
"measurement,tag=value field=\"value\"",
"measurement,tag=value field=true 1729270461612452700",
...
];
let parsed = LineProtocol::parse_vec(lines).unwrap();§Args
lines- An array of InfluxDB line protocol lines
Sourcepub fn parse_lines(lines: &str) -> Result<Vec<Self>, LineProtocolError>
pub fn parse_lines(lines: &str) -> Result<Vec<Self>, LineProtocolError>
Parse multiple lines seprated by a newline (\n)
Empty lines and comment lines are silently ignored
§Example
let lines = vec![
"measurement,tag=value field=\"value\"",
"measurement,tag=value field=true 1729270461612452700",
...
];
let parsed = LineProtocol::parse_lines(lines.join("\n")).unwrap();§Args
lines- Multiple InfluxDB line protocol lines seperated by a newline
Source§impl LineProtocol
impl LineProtocol
Sourcepub fn get_measurement(&self) -> Measurement
pub fn get_measurement(&self) -> Measurement
Get a cloned version of the measurement
Sourcepub fn get_measurement_ref(&self) -> &Measurement
pub fn get_measurement_ref(&self) -> &Measurement
Get a reference of the measurement
Sourcepub fn get_measurement_mut(&mut self) -> &mut Measurement
pub fn get_measurement_mut(&mut self) -> &mut Measurement
Get a mutable reference of the measurement
Sourcepub fn get_tag_ref<K>(&self, key: K) -> Option<&TagValue>
pub fn get_tag_ref<K>(&self, key: K) -> Option<&TagValue>
Sourcepub fn get_tag_mut<K>(&mut self, key: K) -> Option<&mut TagValue>
pub fn get_tag_mut<K>(&mut self, key: K) -> Option<&mut TagValue>
Sourcepub fn get_field<K>(&self, key: K) -> Option<FieldValue>
pub fn get_field<K>(&self, key: K) -> Option<FieldValue>
Sourcepub fn get_field_ref<K>(&self, key: K) -> Option<&FieldValue>
pub fn get_field_ref<K>(&self, key: K) -> Option<&FieldValue>
Sourcepub fn get_field_mut<K>(&mut self, key: K) -> Option<&mut FieldValue>
pub fn get_field_mut<K>(&mut self, key: K) -> Option<&mut FieldValue>
Sourcepub fn get_timestamp(&self) -> Option<i64>
pub fn get_timestamp(&self) -> Option<i64>
Get a cloned version of the timestamp
Sourcepub fn get_timestamp_ref(&self) -> Option<&i64>
pub fn get_timestamp_ref(&self) -> Option<&i64>
Get a reference of the timestamp
Sourcepub fn get_timestamp_mut(&mut self) -> Option<&mut i64>
pub fn get_timestamp_mut(&mut self) -> Option<&mut i64>
Get a mutable reference of the timestamp
Trait Implementations§
Source§impl Clone for LineProtocol
impl Clone for LineProtocol
Source§fn clone(&self) -> LineProtocol
fn clone(&self) -> LineProtocol
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more