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
OffsetMappingwhich tracks all text transformations performed by the filter, allowing precise position mapping between original and filtered text.
- Applies the character filter to the provided mutable string
§Trait Bounds
'static: The filter must have a'staticlifetime, meaning it does not contain any references with shorter lifetimes.SendandSync: 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
CharacterFilterClonetrait, which is typically used to allow cloning of trait objects that implementCharacterFilter. This enables dynamic dispatch of cloned filters.
Required Methods§
fn name(&self) -> &str
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".