pub struct Session<'e> { /* private fields */ }Expand description
One typing session: holds the partial pinyin string the user has typed
so far, exposes candidates, and commits on selection. Borrows the
PinyinEngine for the dict + fuzzy config.
Implementations§
Source§impl<'e> Session<'e>
impl<'e> Session<'e>
Sourcepub fn new(engine: &'e PinyinEngine) -> Self
pub fn new(engine: &'e PinyinEngine) -> Self
Open a session against engine. The session holds a borrow for its
lifetime; the engine itself is Send + Sync-compatible (FST is
'static, fuzzy is Copy).
Sourcepub fn input_char(&mut self, c: char)
pub fn input_char(&mut self, c: char)
Append one ASCII character to the input buffer. Non-ASCII or non-letter characters are silently ignored — the IME shell is responsible for filtering at the keyboard layer.
Sourcepub fn backspace(&mut self) -> bool
pub fn backspace(&mut self) -> bool
Drop the last input character, if any. Returns whether anything was removed.
Sourcepub fn candidates(&mut self) -> &[String]
pub fn candidates(&mut self) -> &[String]
Candidates for the current input, considering fuzzy expansion. Result is borrowed from the session’s reused buffer; subsequent calls invalidate the previous slice.
Empty input yields an empty slice.
Sourcepub fn lookup_into(&self, out: &mut Vec<String>)
pub fn lookup_into(&self, out: &mut Vec<String>)
Same as Self::candidates but writes into a caller-owned buffer.
Useful for FFI callers that own the buffer’s lifetime independently
of the session.
Sourcepub fn commit(&mut self, idx: usize) -> Option<String>
pub fn commit(&mut self, idx: usize) -> Option<String>
Commit the candidate at index idx, returning the committed word and
resetting the input buffer. Out-of-range indices yield None and
leave the session untouched.
Side effect: records the pick in the engine’s L0 layer (item 28).
Three consecutive picks of the same (input, word) auto-pin it to
position 0 for that input. Pinyin v0.2 ignores the fuzzy expansion
for L0 attribution — record uses the literal user input string,
matching what dict.exists_in_l1 will accept.