gitql_core/
object.rs

1use super::values::Value;
2
3/// In memory representation of the list of [`Value`] in one Row
4#[derive(Clone, Default)]
5pub struct Row {
6    pub values: Vec<Box<dyn Value>>,
7}
8
9/// In memory representation of the Rows of one [`Group`]
10#[derive(Clone, Default)]
11pub struct Group {
12    pub rows: Vec<Row>,
13}
14
15impl Group {
16    /// Returns true of this group has no rows
17    pub fn is_empty(&self) -> bool {
18        self.rows.is_empty()
19    }
20
21    /// Returns the number of rows in this group
22    pub fn len(&self) -> usize {
23        self.rows.len()
24    }
25}
26
27/// In memory representation of the GitQL Object which has titles and groups
28#[derive(Default)]
29pub struct GitQLObject {
30    pub titles: Vec<String>,
31    pub groups: Vec<Group>,
32}
33
34impl GitQLObject {
35    /// Flat the list of current groups into one main group
36    pub fn flat(&mut self) {
37        let mut rows: Vec<Row> = vec![];
38        for group in &mut self.groups {
39            rows.append(&mut group.rows);
40        }
41
42        self.groups.clear();
43        self.groups.push(Group { rows })
44    }
45
46    /// Returns true of there is no groups
47    pub fn is_empty(&self) -> bool {
48        self.groups.is_empty()
49    }
50
51    /// Returns the number of groups in this Object
52    pub fn len(&self) -> usize {
53        self.groups.len()
54    }
55}