To accept an iterable over string-ish values in a function or method, I’d use something similar to this:
// std::process::Command
pub fn args<I, S>(&mut self, args: I) -> &mut Command
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
Is it possible to achieve something as elegant for structs? My current version:
lazy_static! {
pub static ref LANG_DEFS: HashMap<String, LangDef> = HashMap::from([
(
"rust".to_string(),
LangDef {
filename: "main.rs".into(),
command: vec!["cargo-play".into(), "--quiet".into(), "*.rs".into()],
}
),
]);
}
pub struct LangDef {
pub filename: String,
pub command: Vec<String>,
}
I’d like to keep my options open w.r.t. String
, so &'static str
is not an option.
Edit: Never mind, it’s just a matter of implementing a constructor LangDef::new()
.