gremlin_client/structure/
list.rs

1use crate::GValue;
2
3#[derive(Debug, PartialEq, Clone)]
4pub struct List(Vec<GValue>);
5
6impl List {
7    pub fn new(elements: Vec<GValue>) -> Self {
8        List(elements)
9    }
10
11    pub(crate) fn take(self) -> Vec<GValue> {
12        self.0
13    }
14
15    pub fn iter(&self) -> impl Iterator<Item = &GValue> {
16        self.0.iter()
17    }
18
19    pub fn len(&self) -> usize {
20        self.0.len()
21    }
22
23    pub fn is_empty(&self) -> bool {
24        self.0.is_empty()
25    }
26}
27
28impl std::iter::IntoIterator for List {
29    type Item = GValue;
30    type IntoIter = std::vec::IntoIter<Self::Item>;
31    fn into_iter(self) -> Self::IntoIter {
32        self.0.into_iter()
33    }
34}
35
36impl Into<List> for Vec<GValue> {
37    fn into(self) -> List {
38        List(self)
39    }
40}
41
42impl From<List> for Vec<GValue> {
43    fn from(list: List) -> Self {
44        list.take()
45    }
46}
47
48impl std::ops::Index<usize> for List {
49    type Output = GValue;
50
51    fn index(&self, key: usize) -> &GValue {
52        self.0.get(key).expect("no entry found for key")
53    }
54}