pub enum MessageContent {
Text(String),
Parts(Vec<Value>),
}Expand description
The content of a chat message.
The OpenAI API allows content to be either a plain string or a structured
array of typed content parts (text blocks, image URLs, tool results, etc.).
Both forms are preserved faithfully through serialize/deserialize
round-trips so the proxy never re-shapes data it did not need to touch.
§Serde behaviour
Uses #[serde(untagged)], so the wire representation is unchanged:
Text("hello")→"hello"(JSON string)Parts([…])→[{"type":"text","text":"…"},…](JSON array)
A JSON null or missing content field is handled by the surrounding
Option<MessageContent> with #[serde(default)].
Variants§
Text(String)
Plain UTF-8 text.
Parts(Vec<Value>)
Structured content parts (text, image_url, tool_result, …).
Individual part shapes are defined by the OpenAI API spec and
validated by the model, not here.
Implementations§
Source§impl MessageContent
impl MessageContent
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Borrow the inner string slice when this is plain-text content.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consume into a single flat String.
For Text the string is returned as-is. For Parts all
{"type":"text","text":"…"} entries are concatenated; other part
types (images, etc.) are omitted — callers should only use this when
a plain-text representation is required (e.g. the [System]: prefix
during system-message conversion).
Sourcefn merge_with(self, other: Self) -> Self
fn merge_with(self, other: Self) -> Self
Merge other into self, producing a single combined MessageContent.
self | other | result |
|---|---|---|
| Text | Text | Text joined with "\n\n" |
| Parts | Parts | Parts arrays concatenated |
| Text | Parts | Parts with a leading text block |
| Parts | Text | Parts with a trailing text block |
Empty strings are handled gracefully (no "\n\n" separator when
either side is empty).
Trait Implementations§
Source§impl Clone for MessageContent
impl Clone for MessageContent
Source§fn clone(&self) -> MessageContent
fn clone(&self) -> MessageContent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more