1use std::collections::HashMap;
2use serde::{Deserialize, Serialize};
3use crate::{group::DeserializeGroup, pointer::PakUntypedPointer, query::PakQuery, value::IntoPakValue};
4
5use super::value::PakValue;
6
7pub type PakIndices = HashMap<PakValue, Vec<PakUntypedPointer>>;
8
9#[derive(PartialEq, Debug, Clone, PartialOrd, Deserialize, Serialize)]
14pub struct PakIndex {
15 pub key : String,
16 pub value : PakValue
17}
18
19impl PakIndex {
20 pub fn new<I, V>(key : I, value : V) -> Self where I : PakIndexIdentifier, V : IntoPakValue {
21 Self {
22 key: key.identifier().to_string(),
23 value: value.into_pak_value(),
24 }
25 }
26}
27
28pub trait PakIndexIdentifier {
33 fn identifier(&self) -> &str;
34
35 fn equals<T, V>(&self, other: V) -> PakQuery<T> where T : DeserializeGroup, V : IntoPakValue {
36 PakQuery::equals(self.identifier(), other.into_pak_value())
37 }
38
39 fn less_than<T, V>(&self, other: V) -> PakQuery<T> where T : DeserializeGroup, V : IntoPakValue {
40 PakQuery::less_than(self.identifier(), other.into_pak_value())
41 }
42
43 fn greater_than<T, V>(&self, other: V) -> PakQuery<T> where T : DeserializeGroup, V : IntoPakValue {
44 PakQuery::greater_than(self.identifier(), other.into_pak_value())
45 }
46
47 fn greater_than_or_equal<T, V>(&self, other: V) -> PakQuery<T> where T : DeserializeGroup, V : IntoPakValue {
48 PakQuery::greater_than_or_equal(self.identifier(), other.into_pak_value())
49 }
50
51 fn less_than_or_equal<T, V>(&self, other: V) -> PakQuery<T> where T : DeserializeGroup, V : IntoPakValue {
52 PakQuery::less_than_or_equal(self.identifier(), other.into_pak_value())
53 }
54
55 fn contains_value<T, V>(&self, other : V) -> PakQuery<T> where T : DeserializeGroup, V : IntoPakValue {
56 PakQuery::contains(self.identifier(), other.into_pak_value())
57 }
58}
59
60impl PakIndexIdentifier for String {
61 fn identifier(&self) -> &str {
62 self
63 }
64}
65
66impl <'id> PakIndexIdentifier for &'id str {
67 fn identifier(&self) -> &str {
68 self
69 }
70}