Skip to main content

pite_core/
props.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2use std::collections::HashMap;
3
4/// Typed prop values. New props don't change the tree struct (§12).
5#[derive(Clone, Debug, PartialEq)]
6pub enum PropValue {
7    Str(String),
8    Num(f64),
9    Int(i64),
10    Bool(bool),
11    Vec2(f64, f64),
12}
13
14/// String→value prop map with typed accessors. Unknown props preserved.
15#[derive(Clone, Debug, Default, PartialEq)]
16pub struct Props(pub HashMap<String, PropValue>);
17
18impl Props {
19    pub fn get(&self, key: &str) -> Option<&PropValue> {
20        self.0.get(key)
21    }
22
23    pub fn insert(&mut self, key: impl Into<String>, value: PropValue) {
24        self.0.insert(key.into(), value);
25    }
26}