Struct direkuta::Capture

source ·
pub struct Capture { /* private fields */ }
Expand description

A wrapper around IndexMap<String, String>.

Stores the captures for a given request.

Implementations§

Constructs a new Capture.

Examples
let capture = Capture::new();

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!");

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");
    },
}

Get a value based on key.

This is a wrapper around try_get.

Examples
let mut capture = Capture::new();

capture.set("message", "Hello World!");

println!("{}", capture.get("message"));
Panics

If the key does not exist the function will panic.

If you do not know if the key exists use try_get.

Attempt to get a value based on key as type.

Examples
let mut capture = Capture::new();

capture.set("message", "0");

println!("{:?}", capture.try_get_parse::<u8>("message"));
Panics

If the key does not exist the function will panic.

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.

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.