#[non_exhaustive]pub struct Message {
pub role: Role,
pub content: Vec<ContentBlock>,
pub metadata: Option<MessageMetadata>,
/* private fields */
}Expand description
A message in a conversation (Message).
Every message has a tracking_id. One supplied by the caller or by saved data is kept;
otherwise, or when it is empty, a fresh UUID is minted.
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.role: RoleThe role of the sender.
content: Vec<ContentBlock>The content blocks.
metadata: Option<MessageMetadata>Metadata, not sent to model providers.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, content: Vec<ContentBlock>) -> Self
pub fn new(role: Role, content: Vec<ContentBlock>) -> Self
Creates a message with a fresh tracking id.
Sourcepub fn assistant(text: impl Into<String>) -> Self
pub fn assistant(text: impl Into<String>) -> Self
Creates an assistant message with one text block.
Sourcepub fn tracking_id(&self) -> &str
pub fn tracking_id(&self) -> &str
Durable id that survives session save and restore; stripped before model calls. Read-only:
set it at construction with Message::with_tracking_id.
Sourcepub fn with_tracking_id(self, tracking_id: impl Into<String>) -> Self
pub fn with_tracking_id(self, tracking_id: impl Into<String>) -> Self
Sets the tracking id. An empty id is replaced with a fresh one.
Sourcepub fn with_metadata(self, metadata: MessageMetadata) -> Self
pub fn with_metadata(self, metadata: MessageMetadata) -> Self
Sets the metadata.
Sourcepub fn with_content(self, content: Vec<ContentBlock>) -> Self
pub fn with_content(self, content: Vec<ContentBlock>) -> Self
Replaces the content, keeping the role, tracking id and metadata (with({ content })).
Sourcepub fn from_message_data(data: JsonValue) -> Result<Self>
pub fn from_message_data(data: JsonValue) -> Result<Self>
Parses caller-supplied message data (Message.fromMessageData).
Unlike deserialization, which keeps unknown block types as UnknownBlock so data a newer
SDK saved still loads, this rejects them with Unknown ContentBlockData type (or
Unknown ToolResultContentData type inside a tool result).
§Errors
Returns an error when the data is not a message or holds an unknown block type.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<Message> for InvokeArgs
impl From<Message> for InvokeArgs
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl !RefUnwindSafe for Message
impl !UnwindSafe for Message
impl Freeze for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
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
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<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> ⓘ
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