Skip to main content

CharacterFilter

Trait CharacterFilter 

Source
pub trait CharacterFilter:
    'static
    + Send
    + Sync
    + CharacterFilterClone {
    // Required methods
    fn name(&self) -> &str;
    fn apply(&self, text: &mut String) -> LinderaResult<OffsetMapping>;
}
Expand description

The CharacterFilter trait defines an interface for filters that preprocess text before tokenization.

§Required Methods

  • name(&self) -> &str:

    • Returns the name of the character filter. This can be used for identification or logging purposes.
  • apply_with_offset_mapping(&self, text: &mut String) -> LinderaResult<OffsetMapping>:

    • Applies the character filter to the provided mutable string text.
    • It returns a result containing an OffsetMapping which tracks all text transformations performed by the filter, allowing precise position mapping between original and filtered text.

§Trait Bounds

  • 'static: The filter must have a 'static lifetime, meaning it does not contain any references with shorter lifetimes.
  • Send and Sync: These bounds ensure that the filter can be safely used in multi-threaded contexts, allowing filters to be shared or sent across threads.

§Cloneability

  • This trait requires the CharacterFilterClone trait, which is typically used to allow cloning of trait objects that implement CharacterFilter. This enables dynamic dispatch of cloned filters.

Required Methods§

Source

fn name(&self) -> &str

Source

fn apply(&self, text: &mut String) -> LinderaResult<OffsetMapping>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§