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>) -> Part
pub fn with_filename(self, filename: impl Into<String>) -> Part
Sets the filename on this part.
Sourcepub fn with_media_type(self, media_type: impl Into<String>) -> Part
pub fn with_media_type(self, media_type: impl Into<String>) -> Part
Sets the media type on this part.
Sourcepub fn with_metadata(self, metadata: Value) -> Part
pub fn with_metadata(self, metadata: Value) -> Part
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>) -> Part
pub fn file_bytes(bytes: impl Into<String>) -> Part
Sourcepub fn file(file: FileContent) -> Part
pub fn file(file: FileContent) -> Part
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.
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Part, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Part, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Serialize for Part
impl Serialize for Part
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request