pub struct Pattern { /* private fields */ }
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn parse(&self, s: &str) -> Result<HashMap<String, Value>, String>
pub fn parse(&self, s: &str) -> Result<HashMap<String, Value>, String>
parse the input string based on the pattern, and rename the captured group based on alias.
- if type is specified, then the value will be converted to the specified type.
- if the type is not supported, then the value will be kept as string.
- if the value can’t be converted to the specified type, then an error will be returned.
- if the value can’t be captured, then an empty map will be returned.
§Example
use std::collections::HashMap;
use grok_rs::{Grok, Value};
let grok = Grok::default();
let pattern = grok.compile("%{USERNAME}", false).unwrap();
let result = pattern.parse("admin admin@example.com").unwrap();
let expected = HashMap::from([("USERNAME".to_string(), Value::String("admin".into()))]);
assert_eq!(expected, result);
Examples found in repository?
More examples
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
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