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 {
27 self.fields.len() < other.fields.len() && other.fields.starts_with(self.fields)
28 }
29}
30
31impl Display for IndexSpec {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 let fields = self.fields.join(", ");
34
35 if self.unique {
36 write!(f, "UNIQUE {}({})", self.store, fields)
37 } else {
38 write!(f, "{}({})", self.store, fields)
39 }
40 }
41}