float_pigment_mlp/node/
attribute.rs1use std::cell::RefCell;
2
3use rustc_hash::FxHashMap;
4#[derive(Default)]
5pub struct Attribute {
6 inner: RefCell<FxHashMap<String, String>>,
7}
8
9impl std::fmt::Debug for Attribute {
10 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11 write!(f, "{:?}", self.inner.borrow())
12 }
13}
14
15impl Attribute {
16 pub fn keys(&self) -> Vec<String> {
17 self.inner
18 .borrow()
19 .keys()
20 .map(|x| x.into())
21 .collect::<Vec<String>>()
22 }
23
24 pub fn get(&self, k: &str) -> Option<String> {
25 self.inner.borrow().get_key_value(k).map(|x| x.1.into())
26 }
27
28 pub fn add(&self, key: String, value: String) {
29 self.inner.borrow_mut().insert(key, value);
30 }
31}