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
impl<'de> Deserialize<'de> for Part
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
impl Eq for Part
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> 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