use std::collections::HashSet;
#[derive(Clone, Debug, Default)]
pub struct InstructionArgSet {
pub names: HashSet<String>,
}
impl InstructionArgSet {
pub fn empty() -> Self {
Self {
names: HashSet::new(),
}
}
pub fn from_names(names: impl IntoIterator<Item = String>) -> Self {
Self {
names: names.into_iter().collect(),
}
}
pub fn contains(&self, name: &str) -> bool {
self.names.contains(name)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_instruction_arg_set_empty() {
let args = InstructionArgSet::empty();
assert!(!args.contains("owner"));
assert!(args.names.is_empty());
}
#[test]
fn test_instruction_arg_set_from_names() {
let args = InstructionArgSet::from_names(vec!["owner".to_string(), "amount".to_string()]);
assert!(args.contains("owner"));
assert!(args.contains("amount"));
assert!(!args.contains("other"));
}
}