Skip to main content

UserBlock

Enum UserBlock 

Source
#[non_exhaustive]
pub enum UserBlock { Text { text: String, cache_control: Option<CacheControl>, }, ToolResult { call_id: String, content: ToolResultContent, cache_control: Option<CacheControl>, }, Image { source: Source, cache_control: Option<CacheControl>, }, Document { source: Source, cache_control: Option<CacheControl>, }, }
Expand description

One block inside a Message::User turn.

Free user text, tool results, and inline media (images, documents) all live here because providers route tool results — and the rest of the multimodal surface — back through the user role on the wire.

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

Free user text.

Fields

§text: String

Text content.

§cache_control: Option<CacheControl>

Per-request cache hint. #[serde(skip)] — the cache breakpoint is a per-call directive to the provider, not part of the persisted conversation state, so it is dropped on snapshot round-trip and restored as None.

§

ToolResult

Result of a tool invocation paired with the assistant AssistantBlock::ToolCall of the previous turn (matched by id).

Fields

§call_id: String

Matches the id on the originating AssistantBlock::ToolCall.

§content: ToolResultContent

The tool’s reply. content.is_error flags tool-reported failures separately from the block list, so an error reply can still carry images.

§

Image

Image content rendered inline. Adapters map this to the provider’s image content type (Anthropic image, Chat Completions image_url). Adapters that cannot represent the chosen Source (e.g. a Chat Completions deployment with no vision support) surface a typed error.

Fields

§source: Source

Image source: base64, URL, or provider-side file ID.

§

Document

Document content rendered inline (PDF and similar). Anthropic has a dedicated document content type; Chat Completions does not, so the Azure adapter surfaces a typed UnsupportedContent error and callers downgrade via ChatMiddleware::on_chat_request if they want a text substitute.

Fields

§source: Source

Document source: base64, URL, or provider-side file ID.

Implementations§

Source§

impl UserBlock

Source

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

Build a UserBlock::Text with no cache breakpoint.

Source

pub fn tool_result( call_id: impl Into<String>, content: impl Into<ToolResultContent>, ) -> Self

Build a UserBlock::ToolResult with no cache breakpoint. The content argument is anything that converts into ToolResultContentString and &str produce a single text block with is_error = false. Use ToolResultContent::error to flag a tool-reported failure or ToolResultContent::from_blocks to build a multi-block reply.

Source

pub fn image(source: Source) -> Self

Build a UserBlock::Image with no cache breakpoint.

Source

pub fn document(source: Source) -> Self

Build a UserBlock::Document with no cache breakpoint.

Source

pub fn with_cache_control(self, cache_control: Option<CacheControl>) -> Self

Builder-style helper: set or replace the cache breakpoint on this block. Use None to clear.

Source

pub fn cache_control(&self) -> Option<&CacheControl>

Read the current cache breakpoint, if any.

Trait Implementations§

Source§

impl Clone for UserBlock

Source§

fn clone(&self) -> UserBlock

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 UserBlock

Source§

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

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

impl<'de> Deserialize<'de> for UserBlock

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 UserBlock

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for UserBlock

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 UserBlock

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> 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.
Source§

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