Skip to main content

harmos_domain/model/storage/query/transform/
project.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17
18// Third Party Imports
19
20// Local Imports
21use super::FieldPath;
22use crate::MemorySize;
23use crate::model::storage::codec::{Nested, Repeated, Text, product};
24
25/* === Constants === */
26
27/* === Macros === */
28
29product!(Project { fields: Repeated<Projection> => 1 });
30product!(Projection { field: Nested<FieldPath> => 1, name: Text => 2 });
31
32/* === Type Aliases === */
33
34/* === Structs === */
35
36#[derive(Clone, Debug)]
37pub struct Project {
38    pub fields: Vec<Projection>,
39}
40#[derive(Clone, Debug)]
41pub struct Projection {
42    pub field: FieldPath,
43    pub name: String,
44}
45
46/* === Enums === */
47
48/* === Traits === */
49
50/* === Implementations === */
51
52impl MemorySize for Project {
53    fn memory_size(&self) -> usize {
54        std::mem::size_of::<Self>() + self.fields.memory_size().saturating_sub(std::mem::size_of_val(&self.fields))
55    }
56}
57impl MemorySize for Projection {
58    fn memory_size(&self) -> usize {
59        std::mem::size_of::<Self>() + self.field.memory_size().saturating_sub(std::mem::size_of_val(&self.field)) + self.name.capacity()
60    }
61}
62
63/* === Public Functions === */
64
65/* === Private Functions === */
66
67/* === Tests === */