pub enum Message {
System(SystemMessage),
Assistant(AssistantMessage),
User(UserMessage),
Result(ResultMessage),
StreamEvent(StreamEvent),
RateLimitEvent(RateLimitEvent),
}Expand description
The top-level message type emitted by the Claude Code CLI on stdout.
Each NDJSON line deserialises into one of these variants. The "type"
field drives the outer discriminant; inner subtypes are carried by nested
fields.
Variants§
System(SystemMessage)
A system-level message (e.g., session initialisation, tool list).
Assistant(AssistantMessage)
A message produced by the assistant (Claude).
User(UserMessage)
A user turn in the conversation.
Result(ResultMessage)
The final result message containing cost and usage summary.
StreamEvent(StreamEvent)
A streaming event emitted during tool execution or other async operations.
RateLimitEvent(RateLimitEvent)
A rate limit status event emitted after API calls.
Implementations§
Source§impl Message
impl Message
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Returns the session ID if present on this message variant.
Sourcepub fn is_error_result(&self) -> bool
pub fn is_error_result(&self) -> bool
Returns true if this is a Message::Result that indicates an error.
Sourcepub fn is_stream_event(&self) -> bool
pub fn is_stream_event(&self) -> bool
Returns true if this is a Message::StreamEvent.
Sourcepub fn assistant_text(&self) -> Option<String>
pub fn assistant_text(&self) -> Option<String>
Extract text content from an Message::Assistant message, joining
all ContentBlock::Text blocks with newlines.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
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>,
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more