Module any_patterns

Source
Expand description

An any-pattern matches if one of its subpatterns matches. In hitori syntax it is represented as an array of its subpatterns.

/// `f32` or `f64`
pub struct FloatType;

#[hitori::impl_expr]
impl Expr<usize, char> for FloatType {
    const PATTERN: _ = (
        |ch| ch == 'f',
        [
            (|ch| ch == '3', |ch| ch == '2'),
            (|ch| ch == '6', |ch| ch == '4'),
        ],
    );
}

assert!(hitori::string::starts_with(FloatType, "f64").is_some());
assert!(hitori::string::starts_with(FloatType, "f128").is_none());

equivalent to f(32|64) in regex syntax

§Empty any-pattern

An empty any-pattern is always false.

/// An empty any-pattern
pub struct False;

#[hitori::impl_expr]
impl Expr<usize, char> for False {
    const PATTERN: _ = [];
}

for s in ["Hello, world!", "34", "hitori"] {
    assert!(hitori::string::starts_with(False, s).is_none());
}

Structs§

False
An empty any-pattern
FalseCapture
This is an empty placeholder-struct
FloatType
f32 or f64
FloatTypeCapture
This is an empty placeholder-struct