input_actions/binding/
map.rs

1use crate::{action, binding::Binding};
2use std::collections::HashMap;
3
4/// A mapping of the supported device bindings for specific [`actions`](action::Action).
5#[derive(Debug, Clone)]
6pub struct ActionMap(HashMap<action::Id, Vec<Binding>>);
7
8impl Default for ActionMap {
9	fn default() -> Self {
10		Self(HashMap::new())
11	}
12}
13
14impl ActionMap {
15	/// Bind a list of device inputs to an [`action`](action::Action) by its [`id`](action::Id).
16	pub fn bind(mut self, action: action::Id, bindings: Vec<Binding>) -> Self {
17		self.0.insert(action, bindings);
18		self
19	}
20
21	pub(crate) fn iter(&self) -> std::collections::hash_map::Iter<'_, action::Id, Vec<Binding>> {
22		self.0.iter()
23	}
24}