ito_core/
repo_index.rs

1//! Precomputed index of an Ito repository.
2//!
3//! `RepoIndex` gathers a few commonly-used directory listings and ids from the
4//! `.ito/` working directory.
5
6use std::collections::BTreeSet;
7use std::path::Path;
8
9use crate::error_bridge::IntoCoreResult;
10use crate::errors::CoreResult;
11use ito_common::fs::StdFs;
12
13#[derive(Debug, Default, Clone)]
14/// Directory listings and ids derived from an Ito repo.
15pub struct RepoIndex {
16    /// Full module directory names under `.ito/modules/` (e.g. `014_rust-documentation`).
17    pub module_dir_names: Vec<String>,
18
19    /// Canonical 3-digit module ids extracted from module directory names.
20    pub module_ids: BTreeSet<String>,
21
22    /// Change directory names under `.ito/changes/`.
23    pub change_dir_names: Vec<String>,
24
25    /// Spec directory names under `.ito/specs/`.
26    pub spec_dir_names: Vec<String>,
27}
28
29impl RepoIndex {
30    /// Load a fresh index from `ito_path`.
31    pub fn load(ito_path: &Path) -> CoreResult<Self> {
32        let fs = StdFs;
33        let module_dir_names =
34            ito_domain::discovery::list_module_dir_names(&fs, ito_path).into_core()?;
35        let module_ids = ito_domain::discovery::list_module_ids(&fs, ito_path).into_core()?;
36        let change_dir_names =
37            ito_domain::discovery::list_change_dir_names(&fs, ito_path).into_core()?;
38        let spec_dir_names =
39            ito_domain::discovery::list_spec_dir_names(&fs, ito_path).into_core()?;
40
41        Ok(Self {
42            module_dir_names,
43            module_ids,
44            change_dir_names,
45            spec_dir_names,
46        })
47    }
48}