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: PartContentThe 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
impl Part
Sourcepub fn with_filename(self, filename: impl Into<String>) -> Self
pub fn with_filename(self, filename: impl Into<String>) -> Self
Sets the filename on this part.
Sourcepub fn with_media_type(self, media_type: impl Into<String>) -> Self
pub fn with_media_type(self, media_type: impl Into<String>) -> Self
Sets the media type on this part.
Sourcepub fn with_metadata(self, metadata: Value) -> Self
pub fn with_metadata(self, metadata: Value) -> Self
Sets metadata on this part.
Sourcepub fn text_content(&self) -> Option<&str>
pub fn text_content(&self) -> Option<&str>
Returns the text content of this part, or None if it is not a text part.
Sourcepub fn file_bytes(bytes: impl Into<String>) -> Self
pub fn file_bytes(bytes: impl Into<String>) -> Self
Sourcepub fn file(file: FileContent) -> Self
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<'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.
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.