Skip to main content

TextFormat

Trait TextFormat 

Source
pub trait TextFormat: Serialize {
    // Provided method
    fn fmt_text(&self, _opts: &TextOptions) -> String { ... }
}
Expand description

Transport-agnostic text formatting for tool outputs.

Implement this trait to provide custom human-readable formatting for your tool output types. The formatting is used by both MCP and NAPI servers to produce text alongside JSON data.

The default implementation returns pretty-printed JSON. Types can override fmt_text to provide custom human-friendly formatting.

Provided Methods§

Source

fn fmt_text(&self, _opts: &TextOptions) -> String

Format the value as human-readable text.

Default: pretty-printed JSON. Types can override to provide custom human-friendly formatting.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TextFormat for String

Identity formatter for String: returns the raw string without JSON quoting.

Source§

fn fmt_text(&self, _opts: &TextOptions) -> String

Implementors§