pub struct TurnTracker {
pub turns: Vec<Turn>,
}Expand description
Tracks turn boundaries over a Vec<Message>.
This is a lightweight index — it doesn’t own the messages, just tracks where each turn starts and how many messages it contains.
Fields§
§turns: Vec<Turn>Implementations§
Source§impl TurnTracker
impl TurnTracker
pub fn new() -> Self
Sourcepub fn rebuild(messages: &[Message]) -> Self
pub fn rebuild(messages: &[Message]) -> Self
Rebuild the turn index from an existing message list. Used when loading conversation history from disk.
Sourcepub fn on_user_message(&mut self, msg_idx: usize)
pub fn on_user_message(&mut self, msg_idx: usize)
Notify that a new user message was added at msg_idx.
Closes the previous turn and opens a new Active turn.
── SAFETY INVARIANT ── This method assumes msg_idx >= prev.start_idx (always true when messages are added sequentially). However, after compression, this invariant could be violated if Turn indices are corrupted. We now defend against this by clamping the result.
Sourcepub fn on_message_added(&mut self, msg_idx: usize)
pub fn on_message_added(&mut self, msg_idx: usize)
Notify that a message was appended (assistant text, tool call, tool result). Extends the current active turn’s msg_count.
Sourcepub fn complete_current(&mut self)
pub fn complete_current(&mut self)
Mark the current (last) turn as completed.
Sourcepub fn active_turn(&self) -> Option<&Turn>
pub fn active_turn(&self) -> Option<&Turn>
Get the current (last) active turn, if any.
Sourcepub fn completed_count(&self) -> usize
pub fn completed_count(&self) -> usize
Number of completed turns (available for summarization).
Trait Implementations§
Source§impl Clone for TurnTracker
impl Clone for TurnTracker
Source§fn clone(&self) -> TurnTracker
fn clone(&self) -> TurnTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TurnTracker
impl Debug for TurnTracker
Source§impl Default for TurnTracker
impl Default for TurnTracker
Source§fn default() -> TurnTracker
fn default() -> TurnTracker
Auto Trait Implementations§
impl Freeze for TurnTracker
impl RefUnwindSafe for TurnTracker
impl Send for TurnTracker
impl Sync for TurnTracker
impl Unpin for TurnTracker
impl UnsafeUnpin for TurnTracker
impl UnwindSafe for TurnTracker
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