#[non_exhaustive]pub enum ContentBlock {
Text {
text: String,
},
Thinking {
thinking: String,
signature: Option<String>,
},
ToolCall {
id: String,
name: String,
arguments: Value,
partial_json: Option<String>,
},
Image {
source: ImageSource,
},
Extension {
type_name: String,
data: Value,
},
}Expand description
The atomic unit of all message content.
Different variants are permitted in different message roles:
Text: user, assistant, tool resultThinking: assistant onlyToolCall: assistant onlyImage: user, tool result
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Text
A plain text string.
Thinking
A reasoning / chain-of-thought string with an optional provider signature.
ToolCall
A tool invocation with an ID, tool name, parsed arguments, and an optional partial JSON buffer used during streaming.
Image
Image data from a supported source type.
Fields
§
source: ImageSourceExtension
An extension content block for plugin-defined types.
Allows multimodal plugins to pass structured data without flattening to Text.
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn extract_text(blocks: &[Self]) -> String
pub fn extract_text(blocks: &[Self]) -> String
Extract concatenated text from a slice of content blocks.
Returns the joined text of all Text variants, ignoring other block types.
Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContentBlock
impl Debug for ContentBlock
Source§impl<'de> Deserialize<'de> for ContentBlock
impl<'de> Deserialize<'de> for ContentBlock
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for ContentBlock
impl PartialEq for ContentBlock
Source§impl Serialize for ContentBlock
impl Serialize for ContentBlock
impl Eq for ContentBlock
impl StructuralPartialEq for ContentBlock
Auto Trait Implementations§
impl Freeze for ContentBlock
impl RefUnwindSafe for ContentBlock
impl Send for ContentBlock
impl Sync for ContentBlock
impl Unpin for ContentBlock
impl UnsafeUnpin for ContentBlock
impl UnwindSafe for ContentBlock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more