vyre-build-scan 0.1.0

Build-time filesystem scanner for flat trait-impl registries
Documentation
//! Public configuration types consumed by `build.rs`.

/// Description of one flat responsibility registry to emit from `build.rs`.
///
/// The scanner resolves [`Registry::scan_dir`] under `CARGO_MANIFEST_DIR` and
/// resolves [`Registry::output_file`] under `OUT_DIR`. `output_file` must be a
/// bare file name, which prevents consumer build scripts from writing generated
/// registry files into `src/`.
///
/// # build.rs example
///
/// ```ignore
/// vyre_build_scan::scan(&vyre_build_scan::Registry {
///     scan_dir: "src/enforce/gates",
///     const_name: "ALL_GATES",
///     element_type: "&'static dyn crate::enforce::EnforceGate",
///     item_const_name: "REGISTERED",
///     output_file: "gates_registry.rs",
///     module_prefix: "crate::enforce::gates",
/// });
/// ```
pub struct Registry<'a> {
    /// Source directory relative to the crate manifest, e.g. `"src/gates"`.
    pub scan_dir: &'a str,
    /// Name of the emitted constant slice, e.g. `"ALL_GATES"`.
    pub const_name: &'a str,
    /// Fully-qualified trait the constant slice references, e.g.
    /// `"&dyn crate::gates::EnforceGate"`.
    ///
    /// The emitted slice has type `&[Item]` where `Item` is this string.
    pub element_type: &'a str,
    /// Name of the `pub const` each scanned file must export.
    pub item_const_name: &'a str,
    /// Bare output file name under `$OUT_DIR`, e.g. `"gates_registry.rs"`.
    pub output_file: &'a str,
    /// Module path prefix used when referencing each file's constant.
    ///
    /// For `src/gates/atomics.rs` with `module_prefix = "crate::gates"`,
    /// the emitted entry is `&crate::gates::atomics::REGISTERED`.
    pub module_prefix: &'a str,
}

/// Description of one Rust-source `OpSpec` registry to emit from `build.rs`.
///
/// Use this when operation implementations expose `pub const SPEC: OpSpec` or
/// an associated `impl Type { pub const SPEC: OpSpec = ...; }` and the crate
/// wants a generated `&[&OpSpec]` in `OUT_DIR`.
///
/// # build.rs example
///
/// ```ignore
/// vyre_build_scan::scan_rust_specs(&vyre_build_scan::RustSpecRegistry {
///     scan_dirs: &["src/ops"],
///     const_name: "GENERATED_REGISTRY",
///     output_file: "ops_registry.rs",
/// });
/// ```
pub struct RustSpecRegistry<'a> {
    /// Source directories relative to the crate manifest, e.g. `"src/ops"`.
    pub scan_dirs: &'a [&'a str],
    /// Name of the emitted slice, e.g. `"GENERATED_REGISTRY"`.
    pub const_name: &'a str,
    /// Bare output file name under `$OUT_DIR`, e.g. `"ops_registry.rs"`.
    pub output_file: &'a str,
}