#[non_exhaustive]pub enum ContentBlock {
Text {
text: String,
},
Image {
source: ImageSource,
},
ToolCall {
id: String,
name: String,
arguments: String,
},
Reasoning {
text: String,
signature: Option<String>,
},
Other {
type_name: String,
data: ExtraMap,
},
}Expand description
A single block of content returned by an LLM provider.
Uses custom serde to produce a flat {"type": "...", ...} JSON shape
rather than Rust’s default externally-tagged enum encoding.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text
Plain text output block
Image
Image output block
Fields
source: ImageSourceImage payload returned by the provider.
ToolCall
Tool call block emitted by the model
Fields
Reasoning
Reasoning block emitted by the model
Fields
Other
Catch-all for content blocks the portable enum does not model.
type_name carries the wire-level "type" discriminator and data
holds the rest of the block’s fields verbatim. Serialization re-emits
the original flat {"type": type_name, ...data} shape, so unknown
block kinds round-trip losslessly through
ChatResponseRecord.
Provider crates translate unrecognized wire block types into Other
rather than dropping them, which preserves provider-specific content
for callers that opt into reading it. Application code typically
inspects type_name and either handles known provider extensions or
treats the block as opaque.
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn as_image(&self) -> Option<ImageBlockRef<'_>>
pub fn as_image(&self) -> Option<ImageBlockRef<'_>>
Borrow the image content for an image block without cloning it.
Sourcepub fn as_tool_call(&self) -> Option<ToolCallRef<'_>>
pub fn as_tool_call(&self) -> Option<ToolCallRef<'_>>
Borrow the tool call payload for a tool-call block without cloning it.
Sourcepub fn as_reasoning(&self) -> Option<&str>
pub fn as_reasoning(&self) -> Option<&str>
Borrow the reasoning text for a reasoning block.
Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more