Enum Pattern

Source
pub enum Pattern {
    Value(ValuePattern),
    Structure(StructurePattern),
    Meta(MetaPattern),
}

Variants§

Implementations§

Source§

impl Pattern

Source

pub fn parse(input: &str) -> Result<Self>

Parse a pattern expression from a string.

Source

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 whitespace
Source§

impl Pattern

Source

pub fn any_bool() -> Self

Creates a pattern that matches any boolean value.

Source

pub fn bool(value: bool) -> Self

Creates a pattern that matches a specific boolean value.

Source

pub fn any_number() -> Self

Creates a pattern that matches any number value.

Source

pub fn number<T>(value: T) -> Self
where T: Into<f64>,

Creates a pattern that matches a specific number value.

Source

pub fn number_range<A>(range: RangeInclusive<A>) -> Self
where A: Into<f64> + Copy,

Creates a pattern that matches numbers within a range.

Source

pub fn number_greater_than<T>(value: T) -> Self
where T: Into<f64>,

Creates a pattern that matches numbers greater than the specified value.

Source

pub fn number_greater_than_or_equal<T>(value: T) -> Self
where T: Into<f64>,

Creates a pattern that matches numbers greater than or equal to the specified value.

Source

pub fn number_less_than<T>(value: T) -> Self
where T: Into<f64>,

Creates a pattern that matches numbers less than the specified value.

Source

pub fn number_less_than_or_equal<T>(value: T) -> Self
where T: Into<f64>,

Creates a pattern that matches numbers less than or equal to the specified value.

Source

pub fn number_nan() -> Self

Creates a pattern that matches NaN values.

Source

pub fn number_infinity() -> Self

Creates a pattern that matches positive infinity values.

Source

pub fn number_neg_infinity() -> Self

Creates a pattern that matches negative infinity values.

Source

pub fn any_text() -> Self

Creates a pattern that matches any text value.

Source

pub fn text<T: Into<String>>(value: T) -> Self

Creates a pattern that matches a specific text value.

Source

pub fn text_regex(regex: Regex) -> Self

Creates a pattern that matches text using a regex.

Source

pub fn any_byte_string() -> Self

Creates a pattern that matches any byte string value.

Source

pub fn byte_string(value: impl AsRef<[u8]>) -> Self

Creates a pattern that matches a specific byte string value.

Source

pub fn byte_string_regex(regex: Regex) -> Self

Creates a pattern that matches byte strings using a binary regex.

Source

pub fn any_date() -> Self

Creates a pattern that matches any date value.

Source

pub fn date(date: Date) -> Self

Creates a pattern that matches a specific date value.

Source

pub fn date_range(range: RangeInclusive<Date>) -> Self

Creates a pattern that matches dates within a range (inclusive).

Source

pub fn date_earliest(date: Date) -> Self

Creates a pattern that matches dates that are on or after the specified date.

Source

pub fn date_latest(date: Date) -> Self

Creates a pattern that matches dates that are on or before the specified date.

Source

pub fn date_iso8601(iso_string: impl Into<String>) -> Self

Creates a pattern that matches a date by its ISO-8601 string representation.

Source

pub fn date_regex(regex: Regex) -> Self

Creates a pattern that matches dates whose ISO-8601 string representation matches the given regex pattern.

Source

pub fn null() -> Self

Creates a pattern that matches null values.

Source

pub fn any_known_value() -> Self

Creates a pattern that matches any known value.

Source

pub fn known_value(value: KnownValue) -> Self

Creates a pattern that matches a specific known value.

Source

pub fn known_value_named(name: impl Into<String>) -> Self

Creates a pattern that matches a known value by name.

Source

pub fn known_value_regex(regex: Regex) -> Self

Creates a pattern that matches known values using a regex on their names.

Source

pub fn any_digest() -> Self

Creates a pattern that matches any digest value.

Source

pub fn digest(digest: Digest) -> Self

Creates a pattern that matches a specific digest.

Source

pub fn digest_prefix(prefix: impl AsRef<[u8]>) -> Self

Creates a pattern that matches digests with the specified prefix.

Source

pub fn digest_binary_regex(regex: Regex) -> Self

Creates a pattern that matches digests using a binary regex.

Source

pub fn any() -> Self

Creates a pattern that always matches any CBOR value.

Source

pub fn and(patterns: Vec<Pattern>) -> Self

Creates a pattern that matches if all contained patterns match.

Source

pub fn or(patterns: Vec<Pattern>) -> Self

Creates a pattern that matches if any contained pattern matches.

Source

pub fn not_matching(pattern: Pattern) -> Self

Creates a pattern that matches if the inner pattern does not match.

Source

pub fn capture(name: impl AsRef<str>, pattern: Pattern) -> Self

Creates a pattern that captures matches with the given name.

Source

pub fn search(pattern: Pattern) -> Self

Creates a search pattern that recursively searches the entire dCBOR tree.

Source

pub fn repeat(pattern: Pattern, quantifier: Quantifier) -> Self

Creates a pattern that matches with repetition using a quantifier.

Source

pub fn group(pattern: Pattern) -> Self

Creates a pattern that wraps another pattern (matches exactly once).

Source

pub fn sequence(patterns: Vec<Pattern>) -> Self

Creates a sequence pattern that matches patterns in order.

Source

pub fn any_array() -> Self

Creates a pattern that matches any array.

Source

pub fn any_map() -> Self

Creates a pattern that matches any map.

Source§

impl Pattern

Source

pub fn any_tagged() -> Self

Creates a pattern that matches any tagged value.

Source

pub fn tagged(tag: impl Into<Tag>, pattern: Pattern) -> Self

Creates a pattern that matches a tagged item with content pattern.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Pattern

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pattern

Source§

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

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

impl Display for Pattern

Source§

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

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

impl PartialEq for Pattern

Source§

fn eq(&self, other: &Pattern) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for Pattern

Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
Source§

impl Eq for Pattern

Source§

impl StructuralPartialEq for Pattern

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,