#[non_exhaustive]pub struct Part {
pub content: PartContent,
pub metadata: Option<Value>,
pub filename: Option<String>,
pub media_type: Option<String>,
}Expand description
Part represents a container for a section of communication content.
Parts can be purely textual, some sort of file (image, video, etc) or
a structured data blob (i.e. JSON).
On the wire the member that is set names the content, beside the other
fields, and Deserialize is written by hand, beside this type, to read
them in one pass:
{"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 (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.content: PartContentThe content of this part (text, raw, url, or data).
metadata: Option<Value>Optional. metadata associated with this part.
filename: Option<String>An optional filename for the file (e.g., “document.pdf”).
media_type: Option<String>The media_type (MIME type) of the part content (e.g., “text/plain”, “application/json”, “image/png”).
This field is available for all part types.
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>,
impl Eq for Part
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 StructuralPartialEq for Part
Auto Trait Implementations§
impl Forget for Part
impl Freeze for Part
impl Move 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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].