Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The main stateful processor of the Vietnamese Input Method Engine.

It maintains an internal buffer of transformations and produces the correctly marked Vietnamese text.

Implementations§

Source§

impl Engine

Source

pub fn new(input_method: InputMethod) -> Self

Creates a new engine with the specified input method and default configuration.

Source

pub fn with_config(input_method: InputMethod, config: Config) -> Self

Creates a new engine with a specific input method and configuration.

Source

pub fn config(&self) -> Config

Returns the current configuration of the engine.

Source

pub fn set_config(&mut self, config: Config)

Updates the engine configuration.

Source

pub fn input_method(&self) -> InputMethod

Returns a copy of the current input method.

Source

pub fn process(&mut self, s: &str, mode: Mode) -> String

Processes a string of characters and returns the current active word.

Source

pub fn process_str(&mut self, s: &str, mode: Mode) -> &Self

Processes a string of characters and returns a reference to the engine.

Source

pub fn process_key_delta( &mut self, key: char, mode: Mode, ) -> (usize, usize, &str)

Processes a single key and returns the “delta” change required for a text editor.

This is useful for IMEs to update the preedit text efficiently without rewriting the entire word.

§Returns

A tuple containing:

  1. backspaces_chars: Number of characters to delete from the end of the previous preedit.
  2. backspaces_bytes: Number of UTF-8 bytes to delete.
  3. inserted: The new string to append after deletion.
Source

pub fn process_key_delta_into( &mut self, key: char, mode: Mode, inserted: &mut String, ) -> usize

Similar to Self::process_key_delta, but writes the inserted string into a provided buffer.

§Returns

The number of backspaces (characters) to perform.

Source

pub fn process_key(&mut self, key: char, mode: Mode)

Processes a single character.

The mode determines whether to apply Vietnamese transformation rules.

Source

pub fn commit(&mut self)

Clears the active syllable buffer and appends it to the committed text.

Source

pub fn output(&self) -> String

Returns the currently active syllable as a string.

Source

pub fn get_processed_str(&self, options: OutputOptions) -> String

Returns the processed string according to the specified options.

This can be used to get the full text (committed + active) or variations like toneless text.

Source

pub fn is_valid(&self, input_is_full_complete: bool) -> bool

Checks if the current composition forms a valid Vietnamese syllable.

Source

pub fn restore_last_word(&mut self, to_vietnamese: bool)

Restores the last word in the composition to its un-transformed state.

If to_vietnamese is true, it attempts to re-apply Vietnamese transformations.

Source

pub fn remove_last_char(&mut self, refresh_last_tone_target: bool)

Removes the last character from the active composition.

Source

pub fn reset(&mut self)

Resets the engine state, clearing committed and active text.

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