Skip to main content

Session

Struct Session 

Source
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

Source

pub fn mask_vocab_size(&self) -> usize

This session’s vocabulary width.

Source

pub fn mask_word_count(&self) -> usize

The u32 word count a Self::write_mask buffer must have.

Source

pub fn eos_token_id(&self) -> TokenId

This session’s EOS token id.

Source

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.

Source

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.

Source

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.

Source

pub fn advance(&mut self, token: TokenId) -> Result<(), SessionError>

Consumes one token; EOS transitions to Stopped instead of reaching the matcher.

Source

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.

Source

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.

Source

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.

Source

pub fn is_stopped(&self) -> bool

EOS has been committed; every advance raises until Self::reset.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.