use chrono::{DateTime, Utc}; const NAME_MAX_LEN: usize = 125; // + 3 bytes for `...` offset @TODO optional /// The `Index` value pub struct Value { pub time: DateTime, pub node: u64, // Isolate by applying internal filter on value set length: Option, name: Option, } impl Value { /// Create new `Self` with current timestamp pub fn new(node: u64, name: Option, length: Option) -> Self { Self { time: Utc::now(), node, length, name: filter_name(name), } } /// Get reference to the safely constructed `name` member pub fn name(&self) -> Option<&String> { self.name.as_ref() } /// Get reference to the safely constructed `length` member pub fn length(&self) -> Option { self.length } } /// Prevent unexpected memory usage on store values from unknown source fn filter_name(value: Option) -> Option { value.map(|v| { if v.len() > NAME_MAX_LEN { format!("{}...", &v[..NAME_MAX_LEN]) } else { v } }) }