Skip to main content

prov_config/
lib.rs

1//! Pure workspace policy and codec types.
2//!
3//! This crate deliberately contains no filesystem discovery or pointer
4//! resolution. It describes, parses, serializes, and diagnoses workspace
5//! policy values; the `prov` crate applies that policy to a mutable workspace.
6
7mod textdist;
8
9pub mod config;
10pub mod vocabulary;
11
12pub use config::{
13    About, ConfigIssue, ConfigIssueKind, FIELD_TYPES, FieldSpec, Fixity, History, IdStorage,
14    OpenClosed, ROOT_CONFIG_KEY, RelationDef, RelationStyleConfig, SPEC_VERSION, WorkspaceConfig,
15    diagnose, field_type_as_config_str, field_type_from_config_str, is_valid_workspace_id,
16    metadata_format_from_str, metadata_format_str, spec_ahead,
17};
18pub use vocabulary::{Term, Vocabulary};
19
20/// The closest live vocabulary term, if it is within the policy's typo
21/// threshold. Kept as a policy-level operation so callers do not need access
22/// to the crate-private edit-distance implementation.
23pub fn nearest_vocabulary_term(key: &str, candidates: &[String]) -> Option<String> {
24    textdist::nearest_owned(key, candidates)
25}
26
27/// Whether two strings are within the typo threshold used by diagnostics.
28pub fn vocabulary_terms_near(a: &str, b: &str) -> bool {
29    (1..=2).contains(&textdist::levenshtein(a, b))
30}
31
32/// The edit distance when two vocabulary-like strings are near enough to be
33/// considered a typo.
34pub fn vocabulary_distance(a: &str, b: &str) -> Option<usize> {
35    let distance = textdist::levenshtein(a, b);
36    (1..=2).contains(&distance).then_some(distance)
37}