Files
pile/crates/pile-config/src/lib.rs
rm-dr 5aab61bd1b
Some checks failed
CI / Typos (push) Successful in 18s
CI / Build and test (push) Failing after 1m4s
CI / Clippy (push) Successful in 1m56s
Auto-update fts index
2026-02-21 16:03:20 -08:00

86 lines
1.7 KiB
Rust

use serde::Deserialize;
use std::{collections::HashMap, fmt::Debug, path::PathBuf};
mod post;
pub use post::*;
mod misc;
pub use misc::*;
pub static INIT_DB_TOML: &str = include_str!("./config.toml");
#[test]
#[expect(clippy::unwrap_used)]
fn init_db_toml_valid() {
toml::from_str::<ConfigToml>(INIT_DB_TOML).expect("INIT_DB_TOML should be valid TOML");
}
#[derive(Debug, Clone, Deserialize)]
pub struct ConfigToml {
pub dataset: DatasetConfig,
pub schema: HashMap<Label, FieldSpec>,
pub fts: Option<DatasetFts>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DatasetConfig {
/// Must be unique
pub name: Label,
/// Root dir for indices
pub working_dir: Option<PathBuf>,
/// Where to find this field
pub source: HashMap<Label, Source>,
/// How to post-process this field
#[serde(default)]
pub post: Vec<FieldSpecPost>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "lowercase")]
pub enum Source {
/// A directory of FLAC files
Flac { path: OneOrMany<PathBuf> },
}
//
// MARK: schema
//
#[derive(Debug, Clone, Deserialize)]
pub struct FieldSpec {
/// The type of this field
pub r#type: FieldType,
/// How to find this field in a data entry
pub path: OneOrMany<String>,
/// How to post-process this field
#[serde(default)]
pub post: Vec<FieldSpecPost>,
}
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum FieldType {
Text,
}
//
// MARK: fts
//
#[derive(Debug, Clone, Deserialize, Default)]
pub struct DatasetFts {
#[serde(alias = "field")]
pub fields: HashMap<Label, FtsIndexField>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct FtsIndexField {
pub tokenize: bool,
}