You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
367 B
15 lines
367 B
use anyhow::Error;
|
|
use std::str::FromStr;
|
|
|
|
|
|
pub fn parse_or<T, F>(val: Option<String>, f: F) -> Result<T, Error>
|
|
where
|
|
T: FromStr,
|
|
<T as FromStr>::Err: core::error::Error + Send + Sync + 'static,
|
|
F: FnOnce() -> Option<T>
|
|
{
|
|
val.map(|x| x.parse::<T>())
|
|
.transpose()?
|
|
.or_else(f)
|
|
.ok_or_else(|| anyhow::anyhow!("Invalid start"))
|
|
} |