Convey Config creation errors using a Result

This commit is contained in:
Manuel Thalmann 2025-03-19 00:40:42 +01:00
parent dd00502383
commit bb076d6cb6
Signed by: manuth
SSH key fingerprint: SHA256:HsMLC+7kJWALP6YCYCoopxNbUnghwSGLVcG76SECT5c

View file

@ -21,14 +21,14 @@ struct Config {
}
impl Config {
fn new(args: &[String]) -> Config {
fn build(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 3 {
panic!("not enough arguments");
return Err("not enough arguments");
}
let query = args[1].clone();
let file_path = args[2].clone();
Config { query, file_path }
Ok(Config { query, file_path })
}
}