Skip to main content

MatchTarget

Trait MatchTarget 

Source
pub trait MatchTarget<'a> {
    // Required methods
    fn get_input(&self) -> &'a str;
    fn clear_ranges(&mut self);
    fn push_range(&mut self, start: usize, end: usize);
}
Expand description

匹配目标抽象特征。

允许底层匹配函数(如 has_keyword)既可以作为一个单纯的布尔检查器(传入 &str), 也可以作为一个范围捕获器(传入 &mut State),从而避免重复编写匹配逻辑。

Required Methods§

Source

fn get_input(&self) -> &'a str

获取当前正在处理的完整字符串。

Source

fn clear_ranges(&mut self)

清空之前记录的所有匹配区间。

Source

fn push_range(&mut self, start: usize, end: usize)

记录一个新的命中区间 [start, end)。

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<'a> MatchTarget<'a> for &'a str

Source§

fn get_input(&self) -> &'a str

Source§

fn clear_ranges(&mut self)

Source§

fn push_range(&mut self, _start: usize, _end: usize)

Implementors§

Source§

impl<'a> MatchTarget<'a> for &mut State<'a>