pub enum UserContent {
Text(TextBlock),
Image(ImageBlock),
}Expand description
Content that can be sent as part of a user turn.
This is the primary type callers use to build messages.
Variants§
Implementations§
Source§impl UserContent
impl UserContent
Sourcepub fn text(s: impl Into<String>) -> Self
pub fn text(s: impl Into<String>) -> Self
Construct a plain-text UserContent from any string-like value.
§Example
use claude_cli_sdk::types::content::UserContent;
let msg = UserContent::text("Hello, Claude!");Sourcepub fn image_base64(
data: impl Into<String>,
media_type: impl Into<String>,
) -> Result<Self>
pub fn image_base64( data: impl Into<String>, media_type: impl Into<String>, ) -> Result<Self>
Construct a base64-encoded image UserContent, validating the MIME
type and payload size.
§Errors
Returns Error::ImageValidation if:
media_typeis not one ofimage/jpeg,image/png,image/gif,image/webp.data(the base64 string) exceeds 15 MiB.
§Example
use claude_cli_sdk::types::content::UserContent;
let content = UserContent::image_base64("aGVsbG8=", "image/png").unwrap();Sourcepub fn image_url(
url: impl Into<String>,
media_type: impl Into<String>,
) -> Result<Self>
pub fn image_url( url: impl Into<String>, media_type: impl Into<String>, ) -> Result<Self>
Construct a URL-referenced image UserContent, validating the MIME
type hint when provided.
§Errors
Returns Error::ImageValidation if media_type is Some but not in
the allowed MIME type list.
§Example
use claude_cli_sdk::types::content::UserContent;
let content = UserContent::image_url("https://example.com/img.png", "image/png").unwrap();Sourcepub fn image_url_untyped(url: impl Into<String>) -> Self
pub fn image_url_untyped(url: impl Into<String>) -> Self
Construct a URL-referenced image without a MIME type hint.
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Returns the text string if this is a UserContent::Text variant.
Trait Implementations§
Source§impl Clone for UserContent
impl Clone for UserContent
Source§fn clone(&self) -> UserContent
fn clone(&self) -> UserContent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UserContent
impl Debug for UserContent
Source§impl<'de> Deserialize<'de> for UserContent
impl<'de> Deserialize<'de> for UserContent
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
Source§impl From<&str> for UserContent
impl From<&str> for UserContent
Source§impl From<String> for UserContent
impl From<String> for UserContent
Source§impl PartialEq for UserContent
impl PartialEq for UserContent
Source§impl Serialize for UserContent
impl Serialize for UserContent
impl StructuralPartialEq for UserContent
Auto Trait Implementations§
impl Freeze for UserContent
impl RefUnwindSafe for UserContent
impl Send for UserContent
impl Sync for UserContent
impl Unpin for UserContent
impl UnsafeUnpin for UserContent
impl UnwindSafe for UserContent
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,
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>
Converts
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>
Converts
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