Skip to main content

Crate hush_macros

Crate hush_macros 

Source
Expand description

Proc macros for the Hush workflow engine.

Provides:

  • #[hush_op] — auto-register Rust ops via inventory
  • #[hush_model] — shorthand for #[derive(Serialize, Deserialize, Debug, Clone)]

§Usage

use hush_serve::{hush_op, hush_model};

#[hush_model]
struct Conversation { vads: Vec<Vad> }

// Legacy style (untyped):
#[hush_op]
fn double(inputs: &Value) -> Value {
    let x = inputs["x"].as_i64().unwrap();
    serde_json::json!({"result": x * 2})
}

// Typed style (auto-generates serde wrapper):
#[hush_op]
fn classify(conversation: Conversation, threshold: f64) -> ClassifyResult {
    // Pure business logic — no JSON parsing
}

#[hush_op(generator)]
fn each_item(inputs: &Value) -> Value {
    let items = inputs["items"].as_array().unwrap();
    Value::Array(items.iter().map(|i| serde_json::json!({"value": i})).collect())
}

Attribute Macros§

hush_model
Shorthand for #[derive(Serialize, Deserialize, Debug, Clone)].
hush_op
Auto-register a function as a Hush op.
hush_resource
Auto-register a function as a resource factory.