Skip to main content

Session

Struct Session 

Source
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>

Source

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).

Source

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.

Source

pub fn backspace(&mut self) -> bool

Drop the last input character, if any. Returns whether anything was removed.

Source

pub fn reset(&mut self)

Clear the entire input buffer (e.g., on Esc).

Source

pub fn input(&self) -> &str

The raw input string typed so far.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'e> Freeze for Session<'e>

§

impl<'e> RefUnwindSafe for Session<'e>

§

impl<'e> Send for Session<'e>

§

impl<'e> Sync for Session<'e>

§

impl<'e> Unpin for Session<'e>

§

impl<'e> UnsafeUnpin for Session<'e>

§

impl<'e> UnwindSafe for Session<'e>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.