pub trait ArgsExt {
// Required methods
fn get_str(&self, key: &str, action: &str) -> Result<&str, AgentError>;
fn get_opt_str(&self, key: &str) -> Option<&str>;
fn get_u64(&self, key: &str, action: &str) -> Result<u64, AgentError>;
fn get_opt_u64(&self, key: &str) -> Option<u64>;
fn get_f64(&self, key: &str, action: &str) -> Result<f64, AgentError>;
fn get_opt_f64(&self, key: &str) -> Option<f64>;
}Expand description
Extension trait for extracting arguments from JSON values
This trait provides methods for extracting typed values from serde_json::Value
with standardized error messages for missing arguments.
§Example
ⓘ
use serde_json::json;
use limit_cli::tools::browser::args::ArgsExt;
let args = json!({
"url": "https://example.com",
"timeout": 5000,
"optional": "value"
});
// Required arguments
let url = args.get_str("url", "open")?;
let timeout = args.get_u64("timeout", "configure")?;
// Optional arguments
let optional = args.get_opt_str("optional");