cloacina-workflow::input_interface
Rust
Injectable input interface — JSON Schema generation (CLOACI-I-0128).
Canonical home for turning a Rust type into a JSON Schema descriptor and for
the InputSlot contract. Lives in cloacina-workflow (not core cloacina)
because the #[workflow(params(...))] macro emits calls to these helpers into
packaged cdylibs, which depend on cloacina-workflow, not core. Core
cloacina re-exports this module.
Spec: [CLOACI-S-0013]; descriptor decision: [CLOACI-A-0007] (JSON Schema via
schemars).
Re-exports
Section titled “Re-exports”InputSlot(cloacina_api_types::InputSlot)
Structs
Section titled “Structs”struct SchemaProbe<T>
Section titled “struct SchemaProbe<T>”pub
Opt-in schema derivation for accumulator/reactor boundary types (CLOACI-I-0128 Task D).
Unlike workflow params (whose types we control via #[workflow(params(...))]),
computation-graph boundary types are defined in the author’s crate and may
or may not derive schemars::JsonSchema. We do NOT want to force the derive
— so the #[computation_graph] macro can’t unconditionally call
schema_for (that needs the bound at compile time).
Instead the macro emits a probe over [SchemaProbe<T>] that, via autoref
specialization (the stable-Rust dtolnay pattern), resolves to the real
schema when T: JsonSchema and to a permissive {} (“any”) schema otherwise.
Authors opt a boundary type into rich typing simply by adding
#[derive(schemars::JsonSchema)]; types without it degrade to name-only slots
rather than failing to compile.
Usage (what the macro emits)
{ use ::cloacina_workflow::input_interface::{ProbeTyped as _, ProbeFallback as _}; (&::cloacina_workflow::input_interface::SchemaProbe::<MyType>::new()) .probe_input_schema()}Methods
Section titled “Methods”pub
fn new() -> SelfSource
pub fn new() -> Self { SchemaProbe(core::marker::PhantomData) }Traits
Section titled “Traits”trait ProbeTyped
Section titled “trait ProbeTyped”pub
Specific arm of the probe: selected when T: JsonSchema (zero autorefs on a &SchemaProbe<T> receiver), yielding the real derived schema.
Methods
Section titled “Methods”probe_input_schema
Section titled “probe_input_schema”fn probe_input_schema(&self) -> serde_json::ValueSource
fn probe_input_schema(&self) -> serde_json::Value;trait ProbeFallback
Section titled “trait ProbeFallback”pub
Fallback arm of the probe: selected for any T (one autoref on a &SchemaProbe<T> receiver), yielding a permissive “any” schema. Method resolution prefers ProbeTyped whenever its T: JsonSchema bound holds.
Methods
Section titled “Methods”probe_input_schema
Section titled “probe_input_schema”fn probe_input_schema(&self) -> serde_json::ValueSource
fn probe_input_schema(&self) -> serde_json::Value;Functions
Section titled “Functions”fn schema_for
Section titled “fn schema_for”pub
fn schema_for<T: schemars::JsonSchema>() -> serde_json::ValueGenerate a JSON Schema for T as a serde_json::Value.
The macro-generated #[workflow(params(...))] descriptor calls this per
declared param type; accumulator/reactor boundary derivation (Task D) calls
it per boundary type. Returns Value::Null only if the generated schema
fails to serialize (not expected for a well-formed JsonSchema impl).
Source
pub fn schema_for<T: schemars::JsonSchema>() -> serde_json::Value { let root = schemars::SchemaGenerator::default().into_root_schema_for::<T>(); serde_json::to_value(root).unwrap_or(serde_json::Value::Null)}fn default_json
Section titled “fn default_json”pub
fn default_json<T: serde::Serialize>( value: T,) -> Option<serde_json::Value>Serialize a default value to serde_json::Value for an InputSlot::default. Returns None if the value can’t serialize.
Source
pub fn default_json<T: serde::Serialize>(value: T) -> Option<serde_json::Value> { serde_json::to_value(value).ok()}fn slots_to_json
Section titled “fn slots_to_json”pub
fn slots_to_json(slots: &[InputSlot]) -> StringSerialize a slot list to the JSON array string carried across the FFI descriptor entrypoint (InputInterfaceEntry::slots_json). Falls back to an empty array on serialization failure.
Source
pub fn slots_to_json(slots: &[InputSlot]) -> String { serde_json::to_string(slots).unwrap_or_else(|_| "[]".to_string())}