luminos_contracts/support/interacts_with_data/contains/
vec.rs1use super::super::{Contains, InteractsWithData, IntoData};
2
3impl<T> IntoData for Vec<T> {
4 type Item = T;
5 type IntoIter = std::vec::IntoIter<T>;
6
7 fn data(self) -> Self::IntoIter {
8 self.into_iter()
9 }
10}
11
12impl<T: PartialEq> Contains<T> for Vec<T> {
13 fn contains_item(&self, item: &T) -> bool {
14 self.contains(item)
15 }
16}
17
18impl<T: Clone + PartialEq> InteractsWithData for Vec<T> {
19 type Value = Vec<T>;
20 type Item = T;
21
22 fn data(&self) -> &Self::Value {
23 self
24 }
25}
26
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn test_vec_interacts_with_data() {
34 let vec = vec![1, 2, 3, 4];
35
36 assert_eq!(vec.all(), vec![1, 2, 3, 4]);
37
38 assert!(vec.exists(&3));
39 assert!(!vec.exists(&5));
40 }
41}