micromegas_analytics/properties/
property_set.rs1use anyhow::Result;
2use micromegas_transit::value::{Object, Value};
3
4#[derive(Debug, Clone, Copy)]
9pub struct PropertySet<'a> {
10 obj: &'a Object<'a>,
11}
12
13impl<'a> PropertySet<'a> {
14 pub fn new(obj: &'a Object<'a>) -> Self {
15 Self { obj }
16 }
17
18 pub fn empty() -> PropertySet<'static> {
19 static EMPTY: Object<'static> = Object {
20 type_name: "EmptyPropertySet",
21 members: &[],
22 };
23 PropertySet { obj: &EMPTY }
24 }
25
26 pub fn for_each_property<Fun: FnMut(&'a str, &'a str) -> Result<()>>(
28 &self,
29 mut fun: Fun,
30 ) -> Result<()> {
31 for &(key, value) in self.obj.members {
32 if let Value::String(value_str) = value {
33 fun(key, value_str)?;
34 }
35 }
36 Ok(())
37 }
38
39 pub fn object_ptr(&self) -> *const () {
46 self.obj as *const Object as *const ()
47 }
48}
49
50impl<'a> From<&'a Object<'a>> for PropertySet<'a> {
51 fn from(value: &'a Object<'a>) -> Self {
52 Self::new(value)
53 }
54}