Skip to main content

TokenSource

Trait TokenSource 

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

Source

type Token: Hash + Eq

The type of token this source produces. Must be hashable and comparable for equality.

Source

type Tokenizer: Iterator<Item = Self::Token>

An iterator that yields tokens from this source.

Required Methods§

Source

fn tokenize(&self) -> Self::Tokenizer

Creates an iterator that yields all tokens from this source.

Source

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

Source§

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

Implementors§

Source§

impl<'a> TokenSource for ByteLinesWithoutTerminator<'a>

Source§

impl<'a> TokenSource for BStrLines<'a>

Source§

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

Source§

impl<'a> TokenSource for Words<'a>