Skip to main content

orbital_data/
record.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{text_map_from_strings, DataValue};
6
7/// One row of typed values, addressable by field key.
8#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
9pub struct DataRecord {
10    pub id: String,
11    pub values: HashMap<String, DataValue>,
12}
13
14impl DataRecord {
15    pub fn new(id: impl Into<String>, values: HashMap<String, DataValue>) -> Self {
16        Self {
17            id: id.into(),
18            values,
19        }
20    }
21
22    /// Build a record from a string cell map (preview/demo convenience).
23    pub fn from_text_map(id: impl Into<String>, cells: HashMap<String, String>) -> Self {
24        Self {
25            id: id.into(),
26            values: text_map_from_strings(cells),
27        }
28    }
29
30    pub fn get(&self, field: &str) -> Option<&DataValue> {
31        self.values.get(field)
32    }
33}