Skip to main content

ContentBlock

Enum ContentBlock 

Source
pub enum ContentBlock {
    Text {
        text: String,
    },
    Thinking {
        text: String,
    },
    Image {
        mime_type: String,
        source: ImageSource,
    },
    ToolCall {
        tool_call_id: ToolCallId,
        provider_call_id: Option<String>,
        tool_name: String,
        arguments: Value,
    },
    HostedTool {
        activity: HostedToolActivity,
    },
    Citation {
        citation: SourceCitation,
    },
}
Expand description

A provider-neutral message content block.

Variants§

§

Text

Visible text content.

Fields

§text: String

UTF-8 text.

§

Thinking

Model reasoning content that products may choose to hide.

Fields

§text: String

UTF-8 reasoning text.

§

Image

Image content with a MIME type and source.

Fields

§mime_type: String

Image MIME type.

§source: ImageSource

Inline or referenced image source.

§

ToolCall

A request to invoke a named tool.

Fields

§tool_call_id: ToolCallId

Canonical tool-call identifier.

§provider_call_id: Option<String>

Opaque provider identifier used to continue the model conversation.

§tool_name: String

Registered tool name.

§arguments: Value

Provider-neutral JSON arguments.

§

HostedTool

One complete provider-hosted activity, including normalized sources.

Fields

§activity: HostedToolActivity

Validated activity and opaque same-provider continuation state.

§

Citation

A normalized citation associated with assistant text.

Fields

§citation: SourceCitation

Validated cited source and optional provider continuation state.

Implementations§

Source§

impl ContentBlock

Source

pub fn text(text: impl Into<String>) -> Result<Self, ContentValidationError>

Creates a validated visible text block.

§Errors

Returns ContentValidationError::InvalidText when the text is empty, contains a null character, or exceeds MAX_TEXT_BLOCK_BYTES.

Source

pub fn thinking(text: impl Into<String>) -> Result<Self, ContentValidationError>

Creates a validated thinking block.

§Errors

Returns ContentValidationError::InvalidText when the text is empty, contains a null character, or exceeds MAX_TEXT_BLOCK_BYTES.

Source

pub fn inline_image( mime_type: impl Into<String>, data: impl Into<String>, ) -> Result<Self, ContentValidationError>

Creates a validated inline Base64 image block.

§Errors

Returns an error when the MIME type is invalid or the data is empty, oversized, or not valid standard Base64.

Source

pub fn image_reference( mime_type: impl Into<String>, reference: impl Into<String>, ) -> Result<Self, ContentValidationError>

Creates a validated referenced image block.

§Errors

Returns an error when the MIME type or bounded reference is invalid.

Source

pub fn tool_call( tool_call_id: ToolCallId, tool_name: impl Into<String>, arguments: Value, ) -> Result<Self, ContentValidationError>

Creates a validated tool-call block.

§Errors

Returns an error when the tool name is invalid, arguments are not an object, or arguments exceed the byte or nesting limits.

Source

pub fn tool_call_with_provider_id( tool_call_id: ToolCallId, provider_call_id: impl Into<String>, tool_name: impl Into<String>, arguments: Value, ) -> Result<Self, ContentValidationError>

Creates a validated tool-call block that retains its provider identifier.

§Errors

Returns an error when the provider identifier, tool name, or arguments violate their protocol bounds.

Source

pub fn hosted_tool(activity: HostedToolActivity) -> Self

Wraps one validated provider-hosted tool activity.

Source

pub fn citation(citation: SourceCitation) -> Self

Wraps one validated external source citation.

Source

pub fn provider_call_id(&self) -> Option<&str>

Returns the opaque provider identifier for a tool-call block.

Trait Implementations§

Source§

impl Clone for ContentBlock

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ContentBlock

Source§

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

Source§

fn eq(&self, other: &ContentBlock) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ContentBlock

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ContentBlock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.