1use std::fmt::{self, Display};
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub struct IndexSpec {
10 pub store: &'static str,
11 pub fields: &'static [&'static str],
12 pub unique: bool,
13}
14
15impl IndexSpec {
16 #[must_use]
17 pub const fn new(store: &'static str, fields: &'static [&'static str], unique: bool) -> Self {
18 Self {
19 store,
20 fields,
21 unique,
22 }
23 }
24
25 #[must_use]
26 pub fn is_prefix_of(&self, other: &Self) -> bool {
28 self.fields.len() < other.fields.len() && other.fields.starts_with(self.fields)
29 }
30}
31
32impl Display for IndexSpec {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 let fields = self.fields.join(", ");
35
36 if self.unique {
37 write!(f, "UNIQUE {}({})", self.store, fields)
38 } else {
39 write!(f, "{}({})", self.store, fields)
40 }
41 }
42}