pub struct Matches<'a> { /* private fields */ }
Expand description
The Matches
represent matched results from a Pattern
against a provided text.
Implementations§
Source§impl<'a> Matches<'a>
impl<'a> Matches<'a>
Sourcepub fn get(&self, name_or_alias: &str) -> Option<&str>
pub fn get(&self, name_or_alias: &str) -> Option<&str>
Gets the value for the name (or) alias if found, None
otherwise.
Examples found in repository?
examples/simple.rs (line 17)
3fn main() {
4 // Instantiate Grok
5 let mut grok = Grok::default();
6
7 // Add a pattern which might be a regex or an alias
8 grok.add_pattern("USERNAME", r"[a-zA-Z0-9._-]+");
9
10 // Compile the definitions into the pattern you want
11 let pattern = grok
12 .compile("%{USERNAME}", false)
13 .expect("Error while compiling!");
14
15 // Match the compiled pattern against a string
16 match pattern.match_against("root") {
17 Some(m) => println!("Found username {:?}", m.get("USERNAME")),
18 None => println!("No matches found!"),
19 }
20}
Sourcepub fn iter(&'a self) -> MatchesIter<'a> ⓘ
pub fn iter(&'a self) -> MatchesIter<'a> ⓘ
Returns a tuple of key/value with all the matches found.
Note that if no match is found, the value is empty.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Matches<'a>
impl<'a> RefUnwindSafe for Matches<'a>
impl<'a> !Send for Matches<'a>
impl<'a> !Sync for Matches<'a>
impl<'a> Unpin for Matches<'a>
impl<'a> UnwindSafe for Matches<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more