pub enum ContentPart {
Text {
text: String,
},
ToolCall(ToolCall),
ToolResult(ToolResult),
}Expand description
A part of a message’s content
Messages can contain multiple content parts, allowing for rich interactions:
- Text for regular conversation
- Tool calls when the assistant wants to use tools
- Tool results when reporting tool execution outcomes
§Why an enum?
Rust enums are “algebraic data types” - each variant can hold different data. This is perfect for modeling the different types of content a message can have. The compiler ensures we handle all cases.
Variants§
Text
Plain text content
ToolCall(ToolCall)
A request to execute a tool (from assistant)
ToolResult(ToolResult)
The result of a tool execution (from user, in response to tool call)
Implementations§
Source§impl ContentPart
impl ContentPart
Sourcepub fn tool_call(
id: impl Into<String>,
name: impl Into<String>,
arguments: Value,
) -> Self
pub fn tool_call( id: impl Into<String>, name: impl Into<String>, arguments: Value, ) -> Self
Create a tool call content part
Sourcepub fn tool_result_success(
call_id: impl Into<String>,
output: impl Into<String>,
) -> Self
pub fn tool_result_success( call_id: impl Into<String>, output: impl Into<String>, ) -> Self
Create a successful tool result content part
Sourcepub fn tool_result_failure(
call_id: impl Into<String>,
error: impl Into<String>,
) -> Self
pub fn tool_result_failure( call_id: impl Into<String>, error: impl Into<String>, ) -> Self
Create a failed tool result content part
Sourcepub fn is_tool_call(&self) -> bool
pub fn is_tool_call(&self) -> bool
Returns true if this is a tool call
Sourcepub fn is_tool_result(&self) -> bool
pub fn is_tool_result(&self) -> bool
Returns true if this is a tool result
Sourcepub fn as_tool_call(&self) -> Option<&ToolCall>
pub fn as_tool_call(&self) -> Option<&ToolCall>
Extract tool call if this is a tool call part
Sourcepub fn as_tool_result(&self) -> Option<&ToolResult>
pub fn as_tool_result(&self) -> Option<&ToolResult>
Extract tool result if this is a tool result part
Trait Implementations§
Source§impl Clone for ContentPart
impl Clone for ContentPart
Source§impl Debug for ContentPart
impl Debug for ContentPart
Source§impl<'de> Deserialize<'de> for ContentPart
impl<'de> Deserialize<'de> for ContentPart
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
impl Eq for ContentPart
Source§impl PartialEq for ContentPart
impl PartialEq for ContentPart
Source§impl Serialize for ContentPart
impl Serialize for ContentPart
impl StructuralPartialEq for ContentPart
Auto Trait Implementations§
impl Freeze for ContentPart
impl RefUnwindSafe for ContentPart
impl Send for ContentPart
impl Sync for ContentPart
impl Unpin for ContentPart
impl UnsafeUnpin for ContentPart
impl UnwindSafe for ContentPart
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.