Skip to main content

Crate use_match

Crate use_match 

Source
Expand description

§use-match

Reusable match-result primitives for RustUse pattern helpers.

Warning: versions below 0.3.0 are experimental and may change as the workspace matures.

§Example Usage

use use_match::{MatchSpan, TextMatch, contains_match, match_len, slice_match};

let span = MatchSpan { start: 0, end: 4 };
let item = TextMatch {
    value: "rust".to_string(),
    span: span.clone(),
};

assert_eq!(match_len(&span), 4);
assert_eq!(slice_match("rustacean", &span), Some("rust"));
assert!(contains_match(&[item], "rust"));

§Scope

  • string-backed span and match-result primitives
  • safe span validation and slicing helpers
  • small collection helpers for common match access patterns

§Non-Goals

  • regex execution
  • parser AST construction
  • validation result frameworks

§License

Licensed under either of the following, at your option:

  • MIT License
  • Apache License, Version 2.0

Structs§

MatchSpan
A half-open span within a UTF-8 string.
NamedMatch
A matched string value paired with an optional name and span.
TextMatch
A matched string value paired with its span.

Enums§

MatchKind
A conservative classification for how a match was found.

Functions§

contains_match
Returns true when a match list contains the given value.
first_match
Returns the first match in a list.
is_match_span_valid
Returns true when a span is ordered, in bounds, and aligned to character boundaries.
last_match
Returns the last match in a list.
match_is_empty
Returns true when the span length is zero.
match_len
Returns the span length using saturating subtraction.
slice_match
Returns a borrowed slice for a valid span.