Skip to main content

EventHandler

Trait EventHandler 

Source
pub trait EventHandler: Send {
    // Provided methods
    fn on_text(&mut self, text: &str) { ... }
    fn on_tool_use(&mut self, tool: &str, input: &Value) { ... }
    fn on_tool_result(&mut self, result: &str) { ... }
    fn on_error(&mut self, error: &str) { ... }
    fn on_complete(&mut self) { ... }
}
Expand description

Event handler trait for streaming responses.

Implement this trait to handle streaming events from Claude during task execution or interactive sessions.

All methods have default no-op implementations, allowing you to override only the events you care about.

Provided Methods§

Source

fn on_text(&mut self, text: &str)

Called when text content is received from Claude.

§Arguments
  • text - The text content received
Source

fn on_tool_use(&mut self, tool: &str, input: &Value)

Called when Claude starts using a tool.

§Arguments
  • tool - The name of the tool being used
  • input - The input parameters for the tool
Source

fn on_tool_result(&mut self, result: &str)

Called when a tool returns a result.

§Arguments
  • result - The result from the tool execution
Source

fn on_error(&mut self, error: &str)

Called when an error occurs during streaming.

§Arguments
  • error - Description of the error
Source

fn on_complete(&mut self)

Called when the response is complete.

Implementors§