pub enum ContentBlock {
Known(KnownBlock),
Other(Value),
}Expand description
One block of content within a message.
Forward-compatible: unknown type tags deserialize into ContentBlock::Other
with the raw JSON preserved.
Variants§
Known(KnownBlock)
A block whose type is recognized by this SDK version.
Other(Value)
A block whose type is not recognized; the raw JSON is preserved.
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn known(&self) -> Option<&KnownBlock>
pub fn known(&self) -> Option<&KnownBlock>
If this is a known block, return the inner KnownBlock.
Sourcepub fn type_tag(&self) -> Option<&str>
pub fn type_tag(&self) -> Option<&str>
Returns the wire-level type tag for this block, regardless of variant.
For known blocks this returns the snake_case discriminant; for unknown
blocks it returns whatever string the server sent in the type field
(or None if the field was missing or non-string).
Sourcepub fn image_url(url: impl Into<String>) -> Self
pub fn image_url(url: impl Into<String>) -> Self
Convenience constructor for a URL-sourced image block.
use claude_api::messages::ContentBlock;
let block = ContentBlock::image_url("https://example.com/cat.png");
assert_eq!(block.type_tag(), Some("image"));Sourcepub fn image_base64(
media_type: impl Into<String>,
data: impl Into<String>,
) -> Self
pub fn image_base64( media_type: impl Into<String>, data: impl Into<String>, ) -> Self
Convenience constructor for a base64-encoded image block. media_type
is the IANA MIME type (e.g. "image/png"); data is base64.
Sourcepub fn document_text(data: impl Into<String>, title: Option<&str>) -> Self
pub fn document_text(data: impl Into<String>, title: Option<&str>) -> Self
Convenience constructor for an inline-text document block. Cites the
document by title if provided.
use claude_api::messages::ContentBlock;
let block = ContentBlock::document_text("Page contents.", Some("Spec"));
assert_eq!(block.type_tag(), Some("document"));Sourcepub fn document_url(url: impl Into<String>) -> Self
pub fn document_url(url: impl Into<String>) -> Self
Convenience constructor for a URL-sourced document block.
Sourcepub fn text_cached(text: impl Into<String>) -> Self
pub fn text_cached(text: impl Into<String>) -> Self
Convenience constructor: a text block with an ephemeral cache breakpoint at the default (5-minute) TTL. Use this on the last block of a long-lived prefix you expect to reuse across requests.
use claude_api::messages::ContentBlock;
let block = ContentBlock::text_cached("Be concise.");
assert_eq!(block.type_tag(), Some("text"));Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl From<ContentBlock> for MessageContent
impl From<ContentBlock> for MessageContent
Source§fn from(b: ContentBlock) -> Self
fn from(b: ContentBlock) -> Self
Source§impl From<KnownBlock> for ContentBlock
impl From<KnownBlock> for ContentBlock
Source§fn from(k: KnownBlock) -> Self
fn from(k: KnownBlock) -> Self
Source§impl PartialEq for ContentBlock
impl PartialEq for ContentBlock
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more