Skip to main content

dpp_rules/
lib.rs

1//! `dpp-rules` — pure EU ESPR cross-field regulatory rules.
2//!
3//! Rules are grouped by product group module. Batteries, textiles, and electronics are
4//! the active product groups; 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-product group utilities).
28pub mod common;
29
30// Chemical substance rules — REACH, RoHS, EU 2026/405.
31// SVHC lives here rather than under any single product group because REACH Art. 33
32// applies across textiles, electronics, toys, construction, and more.
33pub mod chemicals;
34
35// Active product groups.
36pub mod batteries;
37pub mod electronics;
38pub mod textiles;
39pub mod unsold_goods;
40
41// Lineage rules — how one passport may claim to derive from another. Top-level
42// rather than per product group because the edges are envelope fields every
43// product group carries, and ESPR Art. 11(d) makes the linkage obligation
44// framework-level.
45pub mod lineage;
46
47// Plausibility lints — non-binding findings, never a compliance gate.
48pub mod lint;
49
50// Placeholder product groups — rules to be implemented in a later phase.
51pub mod construction;
52pub mod metals;
53pub mod toys;
54
55// Canonical JCS content hashing — the one hasher shared by the bundle
56// verifier and by downstream evidence/dossier consumers, so an integrity
57// hash cannot drift between the code that writes it and the code that checks it.
58#[cfg(feature = "bundle")]
59pub mod canonical;
60
61// Ruleset-bundle format + verification seam (signed, versioned Compliance
62// Current bundles). Optional: signing and hot-swap runtime state stay
63// host-side; this crate only carries the open format + fail-closed verify.
64#[cfg(feature = "bundle")]
65pub mod bundle;
66
67// ── Crate-root re-exports ────────────────────────────────────────────────────
68// Preserved for backward compatibility with existing callers
69// (dpp-domain adapters, dpp-plugin-sdk::rules).
70
71pub use chemicals::cas::validate_cas_format;
72pub use chemicals::surfactants::{
73    SURFACTANT_BANDS, SurfactantInput, surfactant_band_valid, validate_surfactants,
74};
75pub use chemicals::svhc::{
76    CandidateList, ECHA_CANDIDATE_LIST, ECHA_CANDIDATE_LIST_AS_OF,
77    ECHA_CANDIDATE_LIST_OFFICIAL_COUNT, SVHC_THRESHOLD_PCT, SvhcFinding, SvhcFindingKind,
78    SvhcInput, check_svhc_declarations, check_svhc_declarations_embedded, validate_svhc_substances,
79};
80pub use common::country::country_code_valid;
81pub use textiles::fibre::{
82    FIBRE_SUM_TOLERANCE, FibreInput, fibre_sum_ok, validate_fibre_composition,
83};
84
85/// Compile-checks this crate's README examples.
86///
87/// A README example is a public claim about the API, and nothing else in the
88/// build compiles one. Without this, a README can advertise a function that
89/// does not exist — which is exactly what happened before this harness landed.
90#[cfg(doctest)]
91#[doc = include_str!("../README.md")]
92struct ReadmeDoctests;