problemreductions/registry/
mod.rs1mod dyn_problem;
48mod info;
49pub mod problem_ref;
50pub mod problem_type;
51mod schema;
52pub mod variant;
53
54pub use dyn_problem::{format_metric, DynProblem, LoadedDynProblem};
55pub use info::{ComplexityClass, FieldInfo, ProblemInfo, ProblemMetadata};
56pub use problem_ref::{parse_catalog_problem_ref, require_graph_variant, ProblemRef};
57pub use problem_type::{find_problem_type, find_problem_type_by_alias, problem_types, ProblemType};
58pub use schema::{
59 collect_schemas, FieldInfoJson, ParseProblemCategoryError, ProblemCategory, ProblemSchemaEntry,
60 ProblemSchemaJson, VariantDimension,
61};
62pub use variant::{
63 find_variant_by_alias, find_variant_entry, validate_create_inputs,
64 validate_direct_create_inputs, validate_variant_aliases, validate_variant_parameter_schemas,
65 variant_entries, ConstructProblemFn, ConstructionError, CreateInputCodec, CreateInputInfo,
66 CreateSpec, RandomGenerate, RandomRegistration, VariantEntry,
67};
68
69pub fn construct_dyn(
72 name: &str,
73 variant: &BTreeMap<String, String>,
74 data: serde_json::Value,
75) -> Result<Box<dyn DynProblem>, ConstructionError> {
76 let entry = find_variant_entry(name, variant).ok_or_else(|| {
77 ConstructionError::UnregisteredVariant {
78 name: name.to_string(),
79 variant: variant.clone(),
80 }
81 })?;
82 (entry.construct_fn)(data)
83}
84
85use std::any::Any;
86use std::collections::BTreeMap;
87
88pub fn load_dyn(
92 name: &str,
93 variant: &BTreeMap<String, String>,
94 data: serde_json::Value,
95) -> Result<LoadedDynProblem, ConstructionError> {
96 let entry = find_variant_entry(name, variant).ok_or_else(|| {
97 ConstructionError::UnregisteredVariant {
98 name: name.to_string(),
99 variant: variant.clone(),
100 }
101 })?;
102
103 let inner = (entry.factory)(data)
104 .map_err(|error| ConstructionError::InvalidInput(error.to_string()))?;
105 Ok(LoadedDynProblem::new(inner))
106}
107
108pub fn serialize_any(
112 name: &str,
113 variant: &BTreeMap<String, String>,
114 any: &dyn Any,
115) -> Option<serde_json::Value> {
116 let entry = find_variant_entry(name, variant)?;
117 (entry.serialize_fn)(any)
118}
119
120#[cfg(test)]
121#[path = "../unit_tests/registry/dispatch.rs"]
122mod dispatch_tests;