Skip to main content

dpp_rules/
lib.rs

1//! `dpp-rules` — pure EU ESPR cross-field regulatory rules.
2//!
3//! Rules are grouped by sector module. Batteries, textiles, and electronics are
4//! the active sectors; all others have placeholder modules and will be populated
5//! in a later phase.
6//!
7//! Inputs are primitive borrowing views so each caller adapts its own
8//! representation — typed structs in core, `serde_json::Value` fields in
9//! plugins — without this crate depending on either. That is why this crate is
10//! kept separate from `dpp-domain`: a regulatory rule has exactly one
11//! implementation, shared by core and the Wasm plugins alike.
12//!
13//! The `bundle` feature (off by default) adds the ruleset-bundle format +
14//! verification seam (the `bundle` module — conditionally compiled, so not
15//! linked here) and pulls in `std` — see that module's docs.
16
17#![cfg_attr(not(feature = "bundle"), no_std)]
18#![forbid(unsafe_code)]
19
20extern crate alloc;
21
22// Only needed when `no_std` is actually active (default build); when the
23// `bundle` feature is on, `no_std` is off and `std` is already available.
24#[cfg(test)]
25extern crate std;
26
27// Shared helpers (cross-sector utilities).
28pub mod common;
29
30// Chemical substance rules — REACH, RoHS, EU 2026/405.
31// SVHC lives here rather than under any single sector because REACH Art. 33
32// applies across textiles, electronics, toys, construction, and more.
33pub mod chemicals;
34
35// Active sectors.
36pub mod batteries;
37pub mod electronics;
38pub mod textiles;
39
40// Plausibility lints — non-binding findings, never a compliance gate.
41pub mod lint;
42
43// Placeholder sectors — rules to be implemented in a later phase.
44pub mod construction;
45pub mod metals;
46pub mod toys;
47
48// Canonical JCS content hashing — the one hasher shared by the bundle
49// verifier and by downstream evidence/dossier consumers, so an integrity
50// hash cannot drift between the code that writes it and the code that checks it.
51#[cfg(feature = "bundle")]
52pub mod canonical;
53
54// Ruleset-bundle format + verification seam (signed, versioned Compliance
55// Current bundles). Optional: signing and hot-swap runtime state stay
56// engine-side; this crate only carries the open format + fail-closed verify.
57#[cfg(feature = "bundle")]
58pub mod bundle;
59
60// ── Crate-root re-exports ────────────────────────────────────────────────────
61// Preserved for backward compatibility with existing callers
62// (dpp-domain adapters, dpp-plugin-sdk::rules).
63
64pub use chemicals::cas::validate_cas_format;
65pub use chemicals::surfactants::{
66    SURFACTANT_BANDS, SurfactantInput, surfactant_band_valid, validate_surfactants,
67};
68pub use chemicals::svhc::{
69    CandidateListProvenance, ECHA_CANDIDATE_LIST, ECHA_CANDIDATE_LIST_AS_OF,
70    ECHA_CANDIDATE_LIST_OFFICIAL_COUNT, SVHC_THRESHOLD_PCT, SvhcFinding, SvhcFindingKind,
71    SvhcInput, candidate_list_provenance, check_svhc_declarations, validate_svhc_substances,
72};
73pub use common::country::country_code_valid;
74pub use textiles::fibre::{
75    FIBRE_SUM_TOLERANCE, FibreInput, fibre_sum_ok, validate_fibre_composition,
76};
77
78/// Compile-checks this crate's README examples.
79///
80/// A README example is a public claim about the API, and nothing else in the
81/// build compiles one. Without this, a README can advertise a function that
82/// does not exist — which is exactly what happened before this harness landed.
83#[cfg(doctest)]
84#[doc = include_str!("../README.md")]
85struct ReadmeDoctests;