pub struct Capture { /* private fields */ }
Expand description
A wrapper around IndexMap<String, String>.
Stores the captures for a given request.
Implementations§
source§impl Capture
impl Capture
sourcepub fn set(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>)
Sets the value of whatever key is passed.
Please note that you cannot have two of the same keys, one will overwrite the other.
Examples
let mut capture = Capture::new();
capture.set("message", "Hello World!");
sourcepub fn try_get(&self, key: impl Into<String>) -> Option<&str>
pub fn try_get(&self, key: impl Into<String>) -> Option<&str>
Attempt to get a value based on key.
Use this if you are not sure if the key exists.
Examples
let mut capture = Capture::new();
capture.set("message", "Hello World!");
match capture.try_get("message") {
Some(s) => {
println!("{}", s);
},
None => {
println!("Key not found in capture");
},
}
sourcepub fn get_parse<T: FromStr>(&self, key: &str) -> Twhere
T::Err: Debug,
pub fn get_parse<T: FromStr>(&self, key: &str) -> Twhere
T::Err: Debug,
Get a value based on key as type.
This is a wrapper around try_get_parse.
Examples
let mut capture = Capture::new();
capture.set("message", "0");
println!("{}", capture.get_parse::<u8>("message"));
Panics
If the key does not exist the function will panic.
If you do not know if the key exists use try_get_parse
.