Skip to main content

ToolFn

Type Alias ToolFn 

Source
pub type ToolFn = fn(Value, &mut MessageFn) -> Result<Value, ToolError>;
Expand description

Signature of tool functions passed to run_server.

It recieves the inputs of the caller as argument, as well as a instance of MessageFn to log messages and abort on request. It returns the computed value (e.g.: a simulation result, a parsed sequence) or an error, which will be communicated to the client appropriately.

ยงExamples


/// Tool which debug prints the input arguents and returns them to sender.
fn tool(input: Value, send_msg: &mut MessageFn) -> Result<Value, ToolError> {
    send_msg(format!("Args: {input:?}")).map_err(|_| ToolError::Abort)?;
    Ok(input)
}