dpp_calc/kernel/factor.rs
1//! `FactorProvider` trait for injecting licensed LCI emission factor datasets at runtime.
2
3use super::error::CalcError;
4
5// Test/feature-only synthetic provider, kept in its own file so production code
6// never compiles it unless explicitly opted in. Re-exported here to preserve the
7// `factor::SyntheticFactorProvider` path.
8#[cfg(any(test, feature = "synthetic-factors"))]
9pub use super::synthetic_factor::SyntheticFactorProvider;
10
11/// Provides lifecycle-inventory emission factors at runtime.
12///
13/// Implementations inject licensed datasets (ecoinvent, EF, Sphera) without
14/// bundling the underlying data in this Apache-2.0 crate — the methodology is
15/// open, the factor data is licensed and supplied at runtime.
16///
17/// A `FactorProvider` is intentionally *not* used by the Phase-0 calculators
18/// (repairability and the basic CO₂e cradle-to-gate), which take emission
19/// factors as caller-supplied inputs. It will be wired in Phase 2 when the
20/// battery CFB engine requires real LCI data.
21pub trait FactorProvider: Send + Sync {
22 /// Machine-readable identifier of the loaded dataset (e.g. `"ecoinvent-3.10"`).
23 fn dataset_id(&self) -> &str;
24 /// Version string of the loaded dataset.
25 fn dataset_version(&self) -> &str;
26 /// GWP100 characterization factor for an activity identified by its
27 /// dataset-internal UUID, in kg CO₂e per kg of substance emitted.
28 fn gwp100(&self, activity_uuid: &str) -> Result<f64, CalcError>;
29 /// SHA-256 of the full serialised factor table, computed once at provider
30 /// initialisation. Stored in the [`CalculationReceipt`] so a notified body
31 /// can verify that the exact factor values are unchanged between calculations.
32 ///
33 /// [`CalculationReceipt`]: super::receipt::CalculationReceipt
34 fn table_hash(&self) -> &str;
35}