fj_host/
parameters.rs

1use std::{
2    collections::HashMap,
3    ops::{Deref, DerefMut},
4};
5
6/// Parameters that are passed to a model.
7#[derive(Debug, Clone, Eq, PartialEq)]
8pub struct Parameters(pub HashMap<String, String>);
9
10impl Parameters {
11    /// Construct an empty instance of `Parameters`
12    pub fn empty() -> Self {
13        Self(HashMap::new())
14    }
15
16    /// Insert a value into the [`Parameters`] dictionary, implicitly converting
17    /// the arguments to strings and returning `&mut self` to enable chaining.
18    pub fn insert(
19        &mut self,
20        key: impl Into<String>,
21        value: impl ToString,
22    ) -> &mut Self {
23        self.0.insert(key.into(), value.to_string());
24        self
25    }
26}
27
28impl Deref for Parameters {
29    type Target = HashMap<String, String>;
30
31    fn deref(&self) -> &Self::Target {
32        &self.0
33    }
34}
35
36impl DerefMut for Parameters {
37    fn deref_mut(&mut self) -> &mut Self::Target {
38        &mut self.0
39    }
40}