pub enum Pattern {
Value(ValuePattern),
Structure(StructurePattern),
Meta(MetaPattern),
}Variants§
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn parse_partial(input: &str) -> Result<(Self, usize)>
pub fn parse_partial(input: &str) -> Result<(Self, usize)>
Parses a pattern from the beginning of a string and returns both the parsed Pattern and the number of bytes consumed.
Unlike parse(), this function succeeds even if additional
characters follow the first pattern. The returned index points to the
first unparsed character after the pattern.
§Example
let (pattern, consumed) = Pattern::parse_partial("true rest").unwrap();
assert_eq!(pattern, Pattern::bool(true));
assert_eq!(consumed, 5); // "true ".len() - includes whitespaceSource§impl Pattern
impl Pattern
Sourcepub fn any_number() -> Self
pub fn any_number() -> Self
Creates a pattern that matches any number value.
Sourcepub fn number_range<A>(range: RangeInclusive<A>) -> Self
pub fn number_range<A>(range: RangeInclusive<A>) -> Self
Creates a pattern that matches numbers within a range.
Sourcepub fn number_greater_than<T>(value: T) -> Self
pub fn number_greater_than<T>(value: T) -> Self
Creates a pattern that matches numbers greater than the specified value.
Sourcepub fn number_greater_than_or_equal<T>(value: T) -> Self
pub fn number_greater_than_or_equal<T>(value: T) -> Self
Creates a pattern that matches numbers greater than or equal to the specified value.
Sourcepub fn number_less_than<T>(value: T) -> Self
pub fn number_less_than<T>(value: T) -> Self
Creates a pattern that matches numbers less than the specified value.
Sourcepub fn number_less_than_or_equal<T>(value: T) -> Self
pub fn number_less_than_or_equal<T>(value: T) -> Self
Creates a pattern that matches numbers less than or equal to the specified value.
Sourcepub fn number_nan() -> Self
pub fn number_nan() -> Self
Creates a pattern that matches NaN values.
Sourcepub fn number_infinity() -> Self
pub fn number_infinity() -> Self
Creates a pattern that matches positive infinity values.
Sourcepub fn number_neg_infinity() -> Self
pub fn number_neg_infinity() -> Self
Creates a pattern that matches negative infinity values.
Sourcepub fn text<T: Into<String>>(value: T) -> Self
pub fn text<T: Into<String>>(value: T) -> Self
Creates a pattern that matches a specific text value.
Sourcepub fn text_regex(regex: Regex) -> Self
pub fn text_regex(regex: Regex) -> Self
Creates a pattern that matches text using a regex.
Sourcepub fn any_byte_string() -> Self
pub fn any_byte_string() -> Self
Creates a pattern that matches any byte string value.
Sourcepub fn byte_string(value: impl AsRef<[u8]>) -> Self
pub fn byte_string(value: impl AsRef<[u8]>) -> Self
Creates a pattern that matches a specific byte string value.
Sourcepub fn byte_string_regex(regex: Regex) -> Self
pub fn byte_string_regex(regex: Regex) -> Self
Creates a pattern that matches byte strings using a binary regex.
Sourcepub fn date_range(range: RangeInclusive<Date>) -> Self
pub fn date_range(range: RangeInclusive<Date>) -> Self
Creates a pattern that matches dates within a range (inclusive).
Sourcepub fn date_earliest(date: Date) -> Self
pub fn date_earliest(date: Date) -> Self
Creates a pattern that matches dates that are on or after the specified date.
Sourcepub fn date_latest(date: Date) -> Self
pub fn date_latest(date: Date) -> Self
Creates a pattern that matches dates that are on or before the specified date.
Sourcepub fn date_iso8601(iso_string: impl Into<String>) -> Self
pub fn date_iso8601(iso_string: impl Into<String>) -> Self
Creates a pattern that matches a date by its ISO-8601 string representation.
Sourcepub fn date_regex(regex: Regex) -> Self
pub fn date_regex(regex: Regex) -> Self
Creates a pattern that matches dates whose ISO-8601 string representation matches the given regex pattern.
Sourcepub fn any_known_value() -> Self
pub fn any_known_value() -> Self
Creates a pattern that matches any known value.
Sourcepub fn known_value(value: KnownValue) -> Self
pub fn known_value(value: KnownValue) -> Self
Creates a pattern that matches a specific known value.
Sourcepub fn known_value_named(name: impl Into<String>) -> Self
pub fn known_value_named(name: impl Into<String>) -> Self
Creates a pattern that matches a known value by name.
Sourcepub fn known_value_regex(regex: Regex) -> Self
pub fn known_value_regex(regex: Regex) -> Self
Creates a pattern that matches known values using a regex on their names.
Sourcepub fn any_digest() -> Self
pub fn any_digest() -> Self
Creates a pattern that matches any digest value.
Sourcepub fn digest_prefix(prefix: impl AsRef<[u8]>) -> Self
pub fn digest_prefix(prefix: impl AsRef<[u8]>) -> Self
Creates a pattern that matches digests with the specified prefix.
Sourcepub fn digest_binary_regex(regex: Regex) -> Self
pub fn digest_binary_regex(regex: Regex) -> Self
Creates a pattern that matches digests using a binary regex.
Sourcepub fn and(patterns: Vec<Pattern>) -> Self
pub fn and(patterns: Vec<Pattern>) -> Self
Creates a pattern that matches if all contained patterns match.
Sourcepub fn or(patterns: Vec<Pattern>) -> Self
pub fn or(patterns: Vec<Pattern>) -> Self
Creates a pattern that matches if any contained pattern matches.
Sourcepub fn not_matching(pattern: Pattern) -> Self
pub fn not_matching(pattern: Pattern) -> Self
Creates a pattern that matches if the inner pattern does not match.
Sourcepub fn capture(name: impl AsRef<str>, pattern: Pattern) -> Self
pub fn capture(name: impl AsRef<str>, pattern: Pattern) -> Self
Creates a pattern that captures matches with the given name.
Sourcepub fn search(pattern: Pattern) -> Self
pub fn search(pattern: Pattern) -> Self
Creates a search pattern that recursively searches the entire dCBOR tree.
Sourcepub fn repeat(pattern: Pattern, quantifier: Quantifier) -> Self
pub fn repeat(pattern: Pattern, quantifier: Quantifier) -> Self
Creates a pattern that matches with repetition using a quantifier.
Sourcepub fn group(pattern: Pattern) -> Self
pub fn group(pattern: Pattern) -> Self
Creates a pattern that wraps another pattern (matches exactly once).
Source§impl Pattern
impl Pattern
Sourcepub fn any_tagged() -> Self
pub fn any_tagged() -> Self
Creates a pattern that matches any tagged value.
Sourcepub fn tagged(tag: impl Into<Tag>, pattern: Pattern) -> Self
pub fn tagged(tag: impl Into<Tag>, pattern: Pattern) -> Self
Creates a pattern that matches a tagged item with content pattern.
Sourcepub fn tagged_name(name: impl Into<String>, pattern: Pattern) -> Self
pub fn tagged_name(name: impl Into<String>, pattern: Pattern) -> Self
Creates a pattern that matches a tagged item with content pattern and a specific tag name.
Sourcepub fn tagged_regex(regex: Regex, pattern: Pattern) -> Self
pub fn tagged_regex(regex: Regex, pattern: Pattern) -> Self
Creates a pattern that matches a tagged item with content pattern and a regex for the tag name.