Skip to main content

State

Struct State 

Source
pub struct State<'a> {
    pub input: &'a str,
    pub ranges: Vec<UsizeRange>,
}
Expand description

规则执行过程中的中间状态。

随着规则流(flow)的执行,ranges 可能会被修改、过滤或新增, 最终通过的所有 ranges 将作为命中的结果。

Fields§

§input: &'a str

待分析的原始输入文本。

§ranges: Vec<UsizeRange>

当前阶段捕获到的文本范围集合。

Implementations§

Source§

impl<'a> State<'a>

Source

pub fn new(input: &'a str) -> Self

创建一个新的空状态,准备开始规则匹配。

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&'a str, UsizeRange) -> bool,

根据给定的闭包条件,保留符合要求的范围,移除不符合的范围。

此方法常用于在规则的后续步骤中对初步匹配结果进行二次过滤。

Trait Implementations§

Source§

impl<'a> Debug for State<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a str> for State<'a>

Source§

fn from(s: &'a str) -> State<'a>

Converts to this type from the input type.
Source§

impl<'a> From<State<'a>> for RuleResult<'a>

Source§

fn from(state: State<'a>) -> Self

将中间状态 State 转换为最终的 RuleResult。

Source§

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

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)。

Auto Trait Implementations§

§

impl<'a> Freeze for State<'a>

§

impl<'a> RefUnwindSafe for State<'a>

§

impl<'a> Send for State<'a>

§

impl<'a> Sync for State<'a>

§

impl<'a> Unpin for State<'a>

§

impl<'a> UnsafeUnpin for State<'a>

§

impl<'a> UnwindSafe for State<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.