#[non_exhaustive]pub enum ContentBlock {
Text {
text: String,
},
ToolUse {
id: String,
name: String,
input: Value,
},
ToolResult {
tool_use_id: String,
content: String,
is_error: bool,
},
}Expand description
One piece of a message’s content.
A message is a list of blocks rather than a string because a single assistant turn routinely mixes prose with tool calls, and a user turn mixes prose with tool results. Flattening that to text loses the pairing between a call and its result — which is one of the concrete ways a handoff drops context.
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
Plain prose.
ToolUse
The model asking for a tool to be run.
Fields
§
id: StringCorrelates with the matching ContentBlock::ToolResult.
§
name: StringWhich tool — a crate::tool::ToolSpec::name.
ToolResult
The answer to a ContentBlock::ToolUse.
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn tool_use(
id: impl Into<String>,
name: impl Into<String>,
input: Value,
) -> Self
pub fn tool_use( id: impl Into<String>, name: impl Into<String>, input: Value, ) -> Self
A tool call: run name with input; id pairs it with its result.
Sourcepub fn tool_result(
tool_use_id: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn tool_result( tool_use_id: impl Into<String>, content: impl Into<String>, ) -> Self
A successful tool result, answering the call identified by tool_use_id.
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 (const: unstable) · 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§fn eq(&self, other: &ContentBlock) -> bool
fn eq(&self, other: &ContentBlock) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ContentBlock
impl Serialize 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