pub struct Session { /* private fields */ }Expand description
One generation sequence’s mutable state. Never shared between concurrent sequences. Opaque: callers never inspect which backend it wraps.
Implementations§
Source§impl Session
impl Session
Sourcepub fn mask_vocab_size(&self) -> usize
pub fn mask_vocab_size(&self) -> usize
This session’s vocabulary width.
Sourcepub fn mask_word_count(&self) -> usize
pub fn mask_word_count(&self) -> usize
The u32 word count a Self::write_mask buffer must have.
Sourcepub fn eos_token_id(&self) -> TokenId
pub fn eos_token_id(&self) -> TokenId
This session’s EOS token id.
Sourcepub fn mask_byte_count(&self) -> Result<usize, SessionError>
pub fn mask_byte_count(&self) -> Result<usize, SessionError>
Returns the checked buffer length for Self::write_mask_le_bytes.
Callers should use this instead of recomputing mask_word_count() * 4.
Sourcepub fn write_mask(&mut self, mask: &mut [u32]) -> Result<(), SessionError>
pub fn write_mask(&mut self, mask: &mut [u32]) -> Result<(), SessionError>
Fills mask (length must equal Self::mask_word_count) with the allowed-token bitmask; left zeroed on error.
Thin zero-copy wrapper over Self::write_mask_le_bytes.
Sourcepub fn write_mask_le_bytes(
&mut self,
out: &mut [u8],
) -> Result<(), SessionError>
pub fn write_mask_le_bytes( &mut self, out: &mut [u8], ) -> Result<(), SessionError>
Fills out (length must equal Self::mask_byte_count) with the little-endian packed mask; left zeroed on error. Primary zero-extra-allocation path for both backends.
Sourcepub fn advance(&mut self, token: TokenId) -> Result<(), SessionError>
pub fn advance(&mut self, token: TokenId) -> Result<(), SessionError>
Consumes one token; EOS transitions to Stopped instead of reaching the matcher.
Sourcepub fn reset(&mut self) -> Result<(), SessionError>
pub fn reset(&mut self) -> Result<(), SessionError>
Returns to Active at the initial state, discarding any generated prefix. Transactional: builds the replacement before committing, so a failed reset changes nothing.
Sourcepub fn is_accepting(&self) -> bool
pub fn is_accepting(&self) -> bool
Stopping now (committing EOS) would yield a complete, valid instance. Independent of
Self::is_stopped: stays true after stopping too.
Sourcepub fn is_dead(&self) -> bool
pub fn is_dead(&self) -> bool
The permanent dead sink has been reached: no token can ever be legal again. Independent
of Self::is_stopped.
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
EOS has been committed; every advance raises until Self::reset.