peace_item_interaction_model/
item_interactions_current.rs

1use std::ops::{Deref, DerefMut};
2
3use serde::{Deserialize, Serialize};
4
5use crate::ItemInteraction;
6
7/// [`ItemInteraction`]s constructed from parameters derived from fully known
8/// state.
9#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
10pub struct ItemInteractionsCurrent(Vec<ItemInteraction>);
11
12impl ItemInteractionsCurrent {
13    /// Returns a new `ItemInteractionsCurrent` map.
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    /// Returns a new `ItemInteractionsCurrent` map with the given preallocated
19    /// capacity.
20    pub fn with_capacity(capacity: usize) -> Self {
21        Self(Vec::with_capacity(capacity))
22    }
23
24    /// Returns the underlying map.
25    pub fn into_inner(self) -> Vec<ItemInteraction> {
26        self.0
27    }
28}
29
30impl Deref for ItemInteractionsCurrent {
31    type Target = Vec<ItemInteraction>;
32
33    fn deref(&self) -> &Self::Target {
34        &self.0
35    }
36}
37
38impl DerefMut for ItemInteractionsCurrent {
39    fn deref_mut(&mut self) -> &mut Self::Target {
40        &mut self.0
41    }
42}
43
44impl From<Vec<ItemInteraction>> for ItemInteractionsCurrent {
45    fn from(inner: Vec<ItemInteraction>) -> Self {
46        Self(inner)
47    }
48}
49
50impl FromIterator<ItemInteraction> for ItemInteractionsCurrent {
51    fn from_iter<I: IntoIterator<Item = ItemInteraction>>(iter: I) -> Self {
52        Self(Vec::from_iter(iter))
53    }
54}