Skip to content

Commit

Permalink
Make Parameters easier to populate
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jul 17, 2022
1 parent fe68a51 commit c04b84f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::{
collections::{HashMap, HashSet},
ffi::OsStr,
io,
ops::{Deref, DerefMut},
path::PathBuf,
process::Command,
sync::mpsc,
Expand Down Expand Up @@ -254,14 +255,40 @@ impl Watcher {
}
}

/// Parameters that are passed to a model
/// Parameters that are passed to a model.
#[derive(Debug, Clone, PartialEq)]
pub struct Parameters(pub HashMap<String, String>);

impl Parameters {
/// Construct an empty instance of `Parameters`
pub fn empty() -> Self {
Self(HashMap::new())
}

/// Insert a value into the [`Parameters`] dictionary, implicitly converting
/// the arguments to strings and returning `&mut self` to enable chaining.
pub fn insert(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> &mut Self {
self.0.insert(key.into(), value.into());
self
}
}

impl Deref for Parameters {
type Target = HashMap<String, String>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for Parameters {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

/// An error that can occur when loading or reloading a model
Expand Down

0 comments on commit c04b84f

Please sign in to comment.