Skip to main content

Part

Struct Part 

Source
pub struct Part {
    pub content: PartContent,
    pub metadata: Option<Value>,
    pub filename: Option<String>,
    pub media_type: Option<String>,
}
Expand description

A content part within a Message or crate::artifact::Artifact.

In v1.0, Part is a flat structure with a oneof content (text, raw, url, data) plus optional metadata, filename, and mediaType fields. The JSON member name acts as the type discriminator.

§Wire format examples

{"text": "hello"}
{"raw": "base64data", "filename": "f.png", "mediaType": "image/png"}
{"url": "https://example.com/f.pdf", "filename": "f.pdf", "mediaType": "application/pdf"}
{"data": {"key": "value"}, "mediaType": "application/json"}

Fields§

§content: PartContent

The content of this part (text, raw, url, or data).

§metadata: Option<Value>

Arbitrary metadata for this part.

§filename: Option<String>

An optional filename (e.g., “document.pdf”).

§media_type: Option<String>

The media type (MIME type) of the part content.

Implementations§

Source§

impl Part

Source

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

Creates a text Part with the given content.

Source

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

Creates a raw bytes Part (base64-encoded).

Source

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

Creates a URL Part.

Source

pub const fn data(data: Value) -> Self

Creates a data Part carrying structured JSON.

Source

pub fn with_filename(self, filename: impl Into<String>) -> Self

Sets the filename on this part.

Source

pub fn with_media_type(self, media_type: impl Into<String>) -> Self

Sets the media type on this part.

Source

pub fn with_metadata(self, metadata: Value) -> Self

Sets metadata on this part.

Source

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

Returns the text content of this part, or None if it is not a text part.

Source

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

Creates a file Part from raw bytes (base64-encoded).

Deprecated: Use Part::raw instead.

Source

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

Creates a file Part from a URI.

Deprecated: Use Part::url instead.

Source

pub fn file(file: FileContent) -> Self

Creates a file Part from a legacy FileContent struct.

Deprecated: Use Part::raw or Part::url with builder methods.

Trait Implementations§

Source§

impl Clone for Part

Source§

fn clone(&self) -> Part

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Part

Source§

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

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

impl<'de> Deserialize<'de> for Part

Hand-rolled Deserialize for Part that reads all fields in a single pass, avoiding the intermediate serde_json::Value buffering caused by #[serde(flatten)]. This eliminates ~80 allocations per Task deserialize that the derive-based implementation incurred.

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 Part

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Part

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 Eq for Part

Source§

impl StructuralPartialEq for Part

Auto Trait Implementations§

§

impl Freeze for Part

§

impl RefUnwindSafe for Part

§

impl Send for Part

§

impl Sync for Part

§

impl Unpin for Part

§

impl UnsafeUnpin for Part

§

impl UnwindSafe for Part

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>,