cynic_parser/values/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
mod const_lists;
mod const_objects;
mod const_value;
mod enums;
mod lists;
mod objects;
mod scalars;
mod value;
mod variables;

pub mod ids;
pub mod iter;
pub mod writer;

use std::sync::Arc;

pub use self::{
    const_lists::ConstList,
    const_objects::{ConstObject, ConstObjectField},
    const_value::ConstValue,
    enums::EnumValue,
    lists::List,
    objects::{Object, ObjectField},
    scalars::{BooleanValue, FloatValue, IntValue, NullValue, StringValue},
    value::Value,
    variables::VariableValue,
};

use ids::*;
use indexmap::IndexSet;

pub mod storage {
    pub use super::{
        objects::FieldRecord,
        value::{ValueKind, ValueRecord},
    };
}

#[derive(Default)]
pub struct ValueStore {
    strings: Arc<IndexSet<Box<str>>>,

    values: Vec<storage::ValueRecord>,

    fields: Vec<storage::FieldRecord>,
}

impl ValueStore {
    pub fn read<T>(&self, id: T) -> T::Reader<'_>
    where
        T: ValueStoreId,
    {
        id.read(self)
    }
}

#[derive(Clone, Copy)]
struct Cursor<'a, I> {
    id: I,
    store: &'a ValueStore,
}

pub trait ValueStoreId: Copy {
    type Reader<'a>;

    fn read(self, store: &ValueStore) -> Self::Reader<'_>;
}