-
Hi. Following the example given in the documentation, I created a /// Parse a single key-value pair
fn parse_key_val<T: FromStr, U: FromStr>(input: &str) -> Result<Vec<(T, U)>>
where
<T as FromStr>::Err: std::error::Error + Send + Sync + 'static,
<U as FromStr>::Err: std::error::Error + Send + Sync + 'static,
{
input
.trim()
.split(',')
.map(|item| {
let idx = item
.find('=')
.with_context(|| format!("invalid KEY=value: no `=` found in `{}`", input))?;
Ok((input[..idx].parse()?, input[idx + 1..].parse()?))
})
.collect::<Result<Vec<(T, U)>>>()
} And I'm using it as folllowing: #[arg(short, long, env="SETT_METADATA_CUSTOM", value_name="NAME=VALUE", value_parser = parse_key_val::<String, String>)]
metadata: Option<Vec<(String, String)>>, I do not get any error during compile time. However this code panicks on runtime: Mismatch between definition and access of `metadata`. Could not downcast to (alloc::string::String, alloc::string::String), need to downcast to alloc::vec::Vec<(alloc::string::String, alloc::string::String)> Any clue how to solve this? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
To make this more explicit, I'm referring to #[arg(short, long, env="SETT_METADATA_CUSTOM", value_name="NAME=VALUE", value_parser = parse_key_val::<String, String>)]
metadata: Option<std::vec::Vec<(String, String)>>, |
Beta Was this translation helpful? Give feedback.
To make this more explicit, I'm referring to