feat(checker): examples() and spec_files() carry the specification's files
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
A consumer of the checker crate needs no path into this repository. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
1 parent
fc4430c685
commit
73dd967b1a
1983 files changed
+10465
No files matched your search
@@ -7,6 +7,7 @@ repository.workspace = true
|
||||
description = "bookspec's example schema, its rule identifiers and the Engine trait an accounting engine implements."
|
||||
|
||||
[dependencies]
|
||||
include_dir = "0.7"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
toml = "1"
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//! The specification's own files, carried by the crate: a consumer that
|
||||
//! depends on this crate (a git checkout carries the whole repository)
|
||||
//! needs no path to `examples/` or `spec/`.
|
||||
|
||||
use include_dir::{Dir, include_dir};
|
||||
|
||||
static EXAMPLES: Dir<'static> = include_dir!("$CARGO_MANIFEST_DIR/../examples");
|
||||
static SPEC: Dir<'static> = include_dir!("$CARGO_MANIFEST_DIR/../spec");
|
||||
|
||||
/// The files of `dir` whose name ends in `ext`, as (file name, text),
|
||||
/// sorted by name.
|
||||
fn texts(dir: &'static Dir<'static>, ext: &str) -> Vec<(&'static str, &'static str)> {
|
||||
let mut out: Vec<_> = dir
|
||||
.files()
|
||||
.filter_map(|f| {
|
||||
let name = f.path().file_name()?.to_str()?;
|
||||
name.ends_with(ext)
|
||||
.then(|| (name, f.contents_utf8().expect("a UTF-8 file")))
|
||||
})
|
||||
.collect();
|
||||
out.sort();
|
||||
out
|
||||
}
|
||||
|
||||
/// Every example (`examples/*.toml`) as (file name, text), sorted by name.
|
||||
#[must_use]
|
||||
pub fn examples() -> Vec<(&'static str, &'static str)> {
|
||||
texts(&EXAMPLES, ".toml")
|
||||
}
|
||||
|
||||
/// Every specification file (`spec/*.md`) as (file name, text), sorted by
|
||||
/// name.
|
||||
#[must_use]
|
||||
pub fn spec_files() -> Vec<(&'static str, &'static str)> {
|
||||
texts(&SPEC, ".md")
|
||||
}
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
pub mod derive;
|
||||
pub mod engine;
|
||||
pub mod files;
|
||||
pub mod rules;
|
||||
pub mod schema;
|
||||
|
||||
pub use derive::{Derivation, Derived, derive};
|
||||
pub use engine::{Claims, Engine, Refusal, RuleId, RuleIdError, fallback_refusal};
|
||||
pub use files::{examples, spec_files};
|
||||
pub use rules::{Area, Rule, Status, covered_rules, rule, rule_for_id, rule_for_refusal, rules};
|
||||
pub use schema::*;
|
||||
Reference in new issue
Block a user