Enum Searcher

Source
pub enum Searcher {
    And {
        lhs: Box<Searcher>,
        rhs: Box<Searcher>,
    },
    Or {
        lhs: Box<Searcher>,
        rhs: Box<Searcher>,
    },
    Not {
        lhs: Box<Searcher>,
    },
    Tag {
        regex: Regex,
    },
    Equal {
        tag_regex: Regex,
        value_regex: Regex,
    },
    Less {
        tag_regex: Regex,
        value: i32,
    },
    LessEqual {
        tag_regex: Regex,
        value: i32,
    },
    Greater {
        tag_regex: Regex,
        value: i32,
    },
    GreaterEqual {
        tag_regex: Regex,
        value: i32,
    },
}
Expand description

Searcher variants.

Variants§

§

And

Logical and.

Fields

§

Or

Logical or.

Fields

§

Not

Logical not.

Fields

§

Tag

Matches tag.

Fields

§regex: Regex
§

Equal

Matches value.

Fields

§tag_regex: Regex
§value_regex: Regex
§

Less

Matches if integer value is less than value.

Fields

§tag_regex: Regex
§value: i32
§

LessEqual

Matches if integer value is less or equal than rhs.

Fields

§tag_regex: Regex
§value: i32
§

Greater

Matches if integer value is greater than rhs.

Fields

§tag_regex: Regex
§value: i32
§

GreaterEqual

Matches if integer value is greater or equal than rhs.

Fields

§tag_regex: Regex
§value: i32

Implementations§

Source§

impl Searcher

Source

pub fn new_and(lhs: Searcher, rhs: Searcher) -> Self

Returns new and Searcher.

Matches when both elements match. Uses short-circuit evaluation. That means that when the left arm is already false, the right arm is not executed.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("foo".to_string(), None);
tags.insert("bar".to_string(), None);
let search = Searcher::new_and(Searcher::new_tag("foo").unwrap(), Searcher::new_tag("bar").unwrap());
assert!(search.is_match(&tags) == true);
Source

pub fn new_or(lhs: Searcher, rhs: Searcher) -> Self

Returns new or Searcher.

Matches when at least one element matches. Uses short-circuit evaluation. That means that when the left arm matches already, the right arm is not executed.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("foo".to_string(), None);
let search = Searcher::new_or(Searcher::new_tag("foo").unwrap(), Searcher::new_tag("bar").unwrap());
assert!(search.is_match(&tags) == true);
Source

pub fn new_not(lhs: Searcher) -> Self

Returns new not Searcher.

Matches when the contained element doesn’t match.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("bar".to_string(), None);
let search = Searcher::new_not(Searcher::new_tag("foo").unwrap());
assert!(search.is_match(&tags) == true);
Source

pub fn new_tag(regex: &str) -> Result<Self>

Returns new tag Searcher.

Matches when the regular expression matches. The expression is expanded with anchors to match the whole tag.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("foo".to_string(), None);
let search = Searcher::new_tag("foo").unwrap();
assert!(search.is_match(&tags) == true);
§Errors
  • XTagError::Regex if the regex argument is not a valid regular expression
Source

pub fn new_equal(tag_regex: &str, value_regex: &str) -> Result<Self>

Returns new equal Searcher.

tag_regex specifies which tags are checked and value_regex is matched against the associated values. Matches when one value of one matching tag matches. The regular expressions are expanded with anchors to match the whole tag or value.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("bar".to_string(), Some("foo".to_string()));
tags.insert("baz".to_string(), Some("qux".to_string()));
let search = Searcher::new_equal("ba.", "qu.").unwrap();
assert!(search.is_match(&tags) == true);
§Errors
  • XTagError::Regex if tag_regex or value_regex are not a valid regular expression
Source

pub fn new_inequal(tag_regex: &str, value_regex: &str) -> Result<Self>

Returns Searcher for inequality

Combines an equal and a not searcher to test for inequality

§Errors
  • XTagError::Regex if tag_regex or value_regex are not a valid regular expression
Source

pub fn new_less(tag_regex: &str, value: &str) -> Result<Self>

Returns new less Searcher.

tag_regex specifies which tags are checked and rhs is matched against the integer representation of the associated values. Matches when one value of one matching tag matches. tag_regex is expanded with anchors to match the whole tag. If the value cannot be converted to integer that’s no match.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("bar".to_string(), Some("10".to_string()));
tags.insert("baz".to_string(), Some("100".to_string()));
let search = Searcher::new_less("ba.", "50").unwrap();
assert!(search.is_match(&tags) == true);
§Errors
  • XTagError::Regex if tag_regex is not a valid regular expression
  • XtagError::IntParse if rhs can’t be parsed into an integer
Source

pub fn new_less_equal(tag_regex: &str, value: &str) -> Result<Self>

Returns new less or equal Searcher.

tag_regex specifies which tags are checked and rhs is matched against the integer representation of the associated values. Matches when one value of one matching tag matches. tag_regex is expanded with anchors to match the whole tag. If the value cannot be converted to integer that’s no match.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("bar".to_string(), Some("10".to_string()));
tags.insert("baz".to_string(), Some("100".to_string()));
let search = Searcher::new_less_equal("ba.", "10").unwrap();
assert!(search.is_match(&tags) == true);
Source

pub fn new_greater(tag_regex: &str, value: &str) -> Result<Self>

Returns new greater Searcher.

tag_regex specifies which tags are checked and rhs is matched against the integer representation of the associated values. Matches when one value of one matching tag matches. tag_regex is expanded with anchors to match the whole tag. If the value cannot be converted to integer that’s no match.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("bar".to_string(), Some("10".to_string()));
tags.insert("baz".to_string(), Some("100".to_string()));
let search = Searcher::new_greater("ba.", "50").unwrap();
assert!(search.is_match(&tags) == true);
Source

pub fn new_greater_equal(tag_regex: &str, value: &str) -> Result<Self>

Returns new greater or equal Searcher.

tag_regex specifies which tags are checked and rhs is matched against the integer representation of the associated values. Matches when one value of one matching tag matches. tag_regex is expanded with anchors to match the whole tag. If the value cannot be converted to integer that’s no match.

§Example
let mut tags: XTags = HashMap::new();
tags.insert("bar".to_string(), Some("10".to_string()));
tags.insert("baz".to_string(), Some("100".to_string()));
let search = Searcher::new_greater_equal("ba.", "10").unwrap();
assert!(search.is_match(&tags) == true);
Source

pub fn is_match(&self, tags: &XTags) -> bool

Evaluates Searcher against tags.

Trait Implementations§

Source§

impl Display for Searcher

Source§

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

Doesn’t necessarily reproduce the exact term this Searcher resulted from.

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