pub trait TokenSource {
type Token: Hash + Eq;
type Tokenizer: Iterator<Item = Self::Token>;
// Required methods
fn tokenize(&self) -> Self::Tokenizer;
fn estimate_tokens(&self) -> u32;
}Available on crate feature
blob only.Expand description
A trait for types that can be split into tokens for diffing.
Implementing this trait allows a type to be used with InternedInput to create
interned token sequences for computing diffs. For example, &str implements this trait
by default to split text into lines.
Required Associated Types§
Required Methods§
Sourcefn tokenize(&self) -> Self::Tokenizer
fn tokenize(&self) -> Self::Tokenizer
Creates an iterator that yields all tokens from this source.
Sourcefn estimate_tokens(&self) -> u32
fn estimate_tokens(&self) -> u32
Provides an estimate of the number of tokens this source will produce.
This is used to pre-allocate memory for better performance. The estimate does not need to be exact.
Implementations on Foreign Types§
Source§impl<'a> TokenSource for &'a str
By default, a line diff is produced for a string
impl<'a> TokenSource for &'a str
By default, a line diff is produced for a string
Source§impl<'a> TokenSource for &'a BStr
By default, a line diff is produced for a BStr.
impl<'a> TokenSource for &'a BStr
By default, a line diff is produced for a BStr.
Source§impl<'a> TokenSource for &'a [u8]
By default, a line diff is produced for a bytes
impl<'a> TokenSource for &'a [u8]
By default, a line diff is produced for a bytes
Implementors§
Source§impl<'a> TokenSource for ByteLinesWithoutTerminator<'a>
impl<'a> TokenSource for ByteLinesWithoutTerminator<'a>
Source§impl<'a> TokenSource for BStrLines<'a>
impl<'a> TokenSource for BStrLines<'a>
Source§impl<'a> TokenSource for ByteLines<'a>
By default, a line diff is produced for a string
impl<'a> TokenSource for ByteLines<'a>
By default, a line diff is produced for a string
Source§impl<'a> TokenSource for Lines<'a>
By default, a line diff is produced for a string
impl<'a> TokenSource for Lines<'a>
By default, a line diff is produced for a string