pub struct StreamableParser { /* private fields */ }
Expand description
Incremental parser that can consume tokens one by one.
It keeps track of all tokens seen so far, exposes all fully parsed messages and retains the partially parsed state of the current message.
Implementations§
Source§impl StreamableParser
impl StreamableParser
Sourcepub fn new(encoding: HarmonyEncoding, role: Option<Role>) -> Result<Self>
pub fn new(encoding: HarmonyEncoding, role: Option<Role>) -> Result<Self>
Create a new streaming parser starting with the given role.
pub fn process(&mut self, token: u32) -> Result<&mut Self>
pub fn process_eos(&mut self) -> Result<&mut Self>
Sourcepub fn current_content(&self) -> Result<String>
pub fn current_content(&self) -> Result<String>
Return the textual content of the current message so far.
Sourcepub fn current_role(&self) -> Option<Role>
pub fn current_role(&self) -> Option<Role>
Role of the current message if it has been parsed.
Sourcepub fn current_content_type(&self) -> Option<String>
pub fn current_content_type(&self) -> Option<String>
Current content type if known.
Sourcepub fn last_content_delta(&self) -> Result<Option<String>>
pub fn last_content_delta(&self) -> Result<Option<String>>
Decode the last content delta if available.
Sourcepub fn into_messages(self) -> Vec<Message>
pub fn into_messages(self) -> Vec<Message>
Consume the parser and return all parsed messages.
Sourcepub fn state_json(&self) -> Result<String>
pub fn state_json(&self) -> Result<String>
Expose the current state as a JSON string for Python interop.
Sourcepub fn current_recipient(&self) -> Option<String>
pub fn current_recipient(&self) -> Option<String>
Return the current recipient if known.
Sourcepub fn current_channel(&self) -> Option<String>
pub fn current_channel(&self) -> Option<String>
Return the current channel if known.
Auto Trait Implementations§
impl Freeze for StreamableParser
impl RefUnwindSafe for StreamableParser
impl Send for StreamableParser
impl Sync for StreamableParser
impl Unpin for StreamableParser
impl UnwindSafe for StreamableParser
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
Mutably borrows from an owned value. Read more