-
I am having a problem running my program with a value parser that I've made. I get no compile time errors with the value parser, but I do get a runtime error. The #[derive(Args, Debug)]
struct BuildArgs {
#[arg(short, long, value_parser = path_is_xp)]
source: PathBuf,
#[arg(short, long, value_parser = optional_path_is_xslt)]
target: Option<PathBuf>,
#[arg(short, long)]
verbose: Option<bool>,
}
// path_is_xp definition here... omitted for brevity.
fn optional_path_is_xslt(s: &str) -> Result<Option<PathBuf>, String> {
let p: PathBuf = PathBuf::from_str(s)
.map_err(|_| format!("{s} is not a path."))?;
let extension = match p.extension() {
Some(e) => e,
None => return Err(format!("'{s}' has no extension."))
};
if extension == "xsl" || extension == "xslt" {
Ok(Some(p))
} else {
Err(format!("'{s}' is not an XSLT file."))
}
} My runtime error is this: I can't figure out why. I am returning an What am I doing wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Well, I resolved this. I simply opted to remove the |
Beta Was this translation helpful? Give feedback.
Well, I resolved this. I simply opted to remove the
Option<PathBuf>
from the return result and made itResult<PathBuf, String>
and it runs perfectly fine. The value is still an option inside theBuildArgs
struct.