pub enum Content {
Show 25 variants
Text(TextContent),
TextReasoning(TextReasoningContent),
Data(DataContent),
Uri(UriContent),
Error(ErrorContent),
FunctionCall(FunctionCallContent),
FunctionResult(FunctionResultContent),
Usage(UsageContent),
HostedFile(HostedFileContent),
HostedVectorStore(HostedVectorStoreContent),
CodeInterpreterToolCall(CodeInterpreterToolCallContent),
CodeInterpreterToolResult(CodeInterpreterToolResultContent),
ImageGenerationToolCall(ImageGenerationToolCallContent),
ImageGenerationToolResult(ImageGenerationToolResultContent),
McpServerToolCall(McpServerToolCallContent),
McpServerToolResult(McpServerToolResultContent),
SearchToolCall(SearchToolCallContent),
SearchToolResult(SearchToolResultContent),
ShellToolCall(ShellToolCallContent),
ShellToolResult(ShellToolResultContent),
ShellCommandOutput(ShellCommandOutputContent),
FunctionApprovalRequest(FunctionApprovalRequestContent),
FunctionApprovalResponse(FunctionApprovalResponseContent),
OauthConsentRequest(OauthConsentRequestContent),
Unknown,
}Expand description
The unified content union, discriminated by the type tag.
This is the Rust equivalent of the Python Contents union.
The Content::Unknown variant makes deserialization forward-compatible:
a content item whose type tag is not one of the known variants
deserializes to Unknown rather than failing the whole message. This
mirrors Python’s parse-and-skip behavior for unknown content
(_types.py:2205-2210), except the item is retained as an inert
placeholder instead of being dropped. Unknown carries no data, so it
re-serializes as {"type":"unknown"} (the original tag/fields are not
preserved) and is treated as inert everywhere: it yields no text, no
function call, and is ignored by aggregation/coalescing.
Variants§
Text(TextContent)
TextReasoning(TextReasoningContent)
Data(DataContent)
Uri(UriContent)
Error(ErrorContent)
FunctionCall(FunctionCallContent)
FunctionResult(FunctionResultContent)
Usage(UsageContent)
HostedFile(HostedFileContent)
HostedVectorStore(HostedVectorStoreContent)
CodeInterpreterToolCall(CodeInterpreterToolCallContent)
CodeInterpreterToolResult(CodeInterpreterToolResultContent)
ImageGenerationToolCall(ImageGenerationToolCallContent)
ImageGenerationToolResult(ImageGenerationToolResultContent)
McpServerToolCall(McpServerToolCallContent)
McpServerToolResult(McpServerToolResultContent)
SearchToolCall(SearchToolCallContent)
SearchToolResult(SearchToolResultContent)
ShellToolCall(ShellToolCallContent)
ShellToolResult(ShellToolResultContent)
ShellCommandOutput(ShellCommandOutputContent)
FunctionApprovalRequest(FunctionApprovalRequestContent)
FunctionApprovalResponse(FunctionApprovalResponseContent)
OauthConsentRequest(OauthConsentRequestContent)
Unknown
A content item whose type tag is unknown to this version of the
library. Deserialization falls back to this inert variant instead of
erroring; see the type-level docs.
Implementations§
Source§impl Content
impl Content
Sourcepub fn renders_on_every_provider(&self) -> bool
pub fn renders_on_every_provider(&self) -> bool
The text of this item, if it is text or reasoning content. Whether this content reaches the model on every chat converter this workspace ships.
This is the contract compaction’s minimum-retention logic depends on: a retained message “counts” only if it will still be there after the narrowest converter has had its say. The narrowest converter defines each row, and the evidence is pinned by contract tests in the provider crates themselves, so a converter change that invalidates a row fails a test next to the converter rather than surfacing as a compaction bug:
Text— mapped by every converter, but only when it carries non-whitespace: Anthropic rejects an empty text block with a 400.FunctionCall,FunctionResult— mapped by every converter.Data— only a validdata:URI carrying an image in a format Bedrock’s Converse API accepts (png/jpeg/gif/webp, the narrowest image set in the workspace; Anthropic requires images too), and only as user-turn content — Converse and Anthropic reject an assistant image block outright, so role-aware callers (compaction’s retention check) must not count image data in assistant messages. The URI is validated even whenmedia_typeis set: declaring a type is not the same as carrying one, and Anthropic/Gemini parse the URI before emitting anything.Uri— never. Bedrock’s Converse has no remote-URL image source (inline bytes or S3 only), so a hosted image reference renders nowhere there.TextReasoning— provider-dependent (Anthropic renders it, Gemini and OpenAI Chat Completions drop it), so it does not qualify.- Everything else (hosted tool artifacts, approvals,
Unknown, …) — provider-specific at best.
The check errs conservative on purpose: callers use it to decide whether a fallback turn must be added, and nothing is ever removed on its strength, so under-claiming costs a possibly-redundant message while over-claiming produces an effectively empty request.
pub fn as_text(&self) -> Option<&str>
Sourcepub fn as_function_call(&self) -> Option<&FunctionCallContent>
pub fn as_function_call(&self) -> Option<&FunctionCallContent>
The function call carried by this item, if any.
Sourcepub fn as_function_result(&self) -> Option<&FunctionResultContent>
pub fn as_function_result(&self) -> Option<&FunctionResultContent>
The function result carried by this item, if any.
Sourcepub fn as_function_approval_request(
&self,
) -> Option<&FunctionApprovalRequestContent>
pub fn as_function_approval_request( &self, ) -> Option<&FunctionApprovalRequestContent>
The function-approval request carried by this item, if any.
Sourcepub fn as_function_approval_response(
&self,
) -> Option<&FunctionApprovalResponseContent>
pub fn as_function_approval_response( &self, ) -> Option<&FunctionApprovalResponseContent>
The function-approval response carried by this item, if any.