float_pigment_mlp/node/
attribute.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::cell::RefCell;

use rustc_hash::FxHashMap;
#[derive(Default)]
pub struct Attribute {
    inner: RefCell<FxHashMap<String, String>>,
}

impl std::fmt::Debug for Attribute {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self.inner.borrow())
    }
}

impl Attribute {
    pub fn keys(&self) -> Vec<String> {
        self.inner
            .borrow()
            .keys()
            .map(|x| x.into())
            .collect::<Vec<String>>()
    }

    pub fn get(&self, k: &str) -> Option<String> {
        self.inner.borrow().get_key_value(k).map(|x| x.1.into())
    }

    pub fn add(&self, key: String, value: String) {
        self.inner.borrow_mut().insert(key, value);
    }
}