I'm currently restricted to clap 4.0.9 and I have the following code:
#[derive(Debug, clap::Parser)]
pub struct RunCmd {
#[clap(long, default_value_t = 7000)]
pub port: u16,
}
I want to create a function that validates the port that is passed like this:
fn validate_port(p: &str) -> Result<u16, String> {
let port = p.parse::<u16>().map_err(|_| "Invalid port number")?;
if port >= 1024 {
Ok(port)
} else {
Err("Port number must be between 1024 and 65535".to_owned())
}
}
is there a way to call validate_port to validate the port?