Enum Query

Source
pub enum Query {
    Exact(String, bool),
    StartsWith(String, bool),
    Contains(String, bool),
    EndsWith(String, bool),
}
Expand description

Represents different ways to match input text.

  • Exact(String, bool) matches if the text is exactly equal to the query string.
  • StartsWith(String, bool) matches if the text starts with the query string.
  • Contains(String, bool) matches if the text contains the query string.
  • EndsWith(String, bool) matches if the text ends with the query string.

The bool field indicates whether the match should be case-sensitive (true) or case-insensitive (false). By default, it is case-insensitive unless the query string is prefixed with c: (for “case-sensitive”) or i: (for “case-insensitive”).

Variants§

§

Exact(String, bool)

Variant for an exact match. The second parameter specifies if it’s case-sensitive.

§

StartsWith(String, bool)

Variant for matching if the text starts with the query. The second parameter specifies if it’s case-sensitive.

§

Contains(String, bool)

Variant for matching if the text contains the query. The second parameter specifies if it’s case-sensitive.

§

EndsWith(String, bool)

Variant for matching if the text ends with the query. The second parameter specifies if it’s case-sensitive.

Implementations§

Source§

impl Query

Source

pub fn matches(&self, text: &str) -> bool

Checks whether the given text matches this query.

By default, matches are case-insensitive unless specified otherwise in the query. If case_sensitive is true, the match must respect exact casing.

§Arguments
  • text - The text to check against the query.
§Returns

Returns true if the text matches according to the query variant (respecting case sensitivity), or false otherwise.

§Examples

// Case-insensitive exact match example:
let query = Query::from_str("=Hello").unwrap();
assert!(query.matches("hello"));

// Case-sensitive contains example:
let query = Query::from_str("c:ell").unwrap();
assert!(query.matches("Well")); // false
assert!(query.matches("ell"));  // true if text is exactly "ell"

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Query

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 Query

Source§

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

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

impl FromStr for Query

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string slice into a Query with optional case sensitivity.

The parsing follows a simple syntax:

  • Case Sensitivity:

    • If the string starts with "c:", the query is case-sensitive.
    • If it starts with "i:", the query is explicitly case-insensitive.
    • Otherwise, it defaults to case-insensitive.
  • Match Variants:

    • If, after removing any c: or i: prefix, the string starts with = => parsed as Exact(...).
    • If it starts with ^ => parsed as StartsWith(...).
    • If it ends with $ => parsed as EndsWith(...).
    • Otherwise, it is parsed as Contains(...).

Whitespace is trimmed, and an empty input results in an error.

§Examples

// Case-insensitive exact match
let query = Query::from_str("=Exact").unwrap();
if let Query::Exact(ref s, false) = query {
    assert_eq!(s, "Exact");
} else {
    panic!("Expected case-insensitive Exact variant");
}

// Case-sensitive starts-with match
let query = Query::from_str("c:^Hello").unwrap();
if let Query::StartsWith(ref s, true) = query {
    assert_eq!(s, "Hello");
} else {
    panic!("Expected case-sensitive StartsWith variant");
}
Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

impl PartialEq for Query

Source§

fn eq(&self, other: &Query) -> 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 StructuralPartialEq for Query

Auto Trait Implementations§

§

impl Freeze for Query

§

impl RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnwindSafe for Query

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more