rs_postgres_stat2otel/
row.rs

1//! A row which contains columns.
2
3use std::collections::BTreeMap;
4
5use crate::col::Column;
6
7use opentelemetry::Value;
8
9/// Contains many columns.
10pub struct Row {
11    columns: Vec<Column>,
12}
13
14impl Row {
15    /// Gets columns.
16    pub fn as_columns(&self) -> &[Column] {
17        &self.columns
18    }
19
20    /// Converts to a map.
21    ///
22    /// - Key: The name of the column.
23    /// - Val: The value of the column.
24    pub fn to_map(&self) -> BTreeMap<String, Value> {
25        let i = self.as_columns().iter().map(|c: &Column| {
26            let key: &str = c.as_name();
27            let val: &Value = c.as_value();
28            (String::from(key), val.clone())
29        });
30        BTreeMap::from_iter(i)
31    }
32
33    /// Creates new row from columns.
34    pub fn new(columns: Vec<Column>) -> Self {
35        Self { columns }
36    }
37}