Skip to main content

ArgsExt

Trait ArgsExt 

Source
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");

Required Methods§

Source

fn get_str(&self, key: &str, action: &str) -> Result<&str, AgentError>

Get a required string argument

§Arguments
  • key - The key to look up in the JSON object
  • action - The action name for error reporting
§Returns
  • Ok(&str) - The string value if found
  • Err(AgentError) - If the key is missing or not a string
§Example
let url = args.get_str("url", "open")?;
Source

fn get_opt_str(&self, key: &str) -> Option<&str>

Get an optional string argument

§Arguments
  • key - The key to look up in the JSON object
§Returns
  • Some(&str) - The string value if found
  • None - If the key is missing or not a string
§Example
let path = args.get_opt_str("path");
Source

fn get_u64(&self, key: &str, action: &str) -> Result<u64, AgentError>

Get a required u64 argument

§Arguments
  • key - The key to look up in the JSON object
  • action - The action name for error reporting
§Returns
  • Ok(u64) - The u64 value if found
  • Err(AgentError) - If the key is missing or not a u64
§Example
let index = args.get_u64("index", "tab_select")?;
Source

fn get_opt_u64(&self, key: &str) -> Option<u64>

Get an optional u64 argument

§Arguments
  • key - The key to look up in the JSON object
§Returns
  • Some(u64) - The u64 value if found
  • None - If the key is missing or not a u64
§Example
let pixels = args.get_opt_u64("pixels");
Source

fn get_f64(&self, key: &str, action: &str) -> Result<f64, AgentError>

Get a required f64 argument

§Arguments
  • key - The key to look up in the JSON object
  • action - The action name for error reporting
§Returns
  • Ok(f64) - The f64 value if found
  • Err(AgentError) - If the key is missing or not an f64
§Example
let latitude = args.get_f64("latitude", "set_geo")?;
Source

fn get_opt_f64(&self, key: &str) -> Option<f64>

Get an optional f64 argument

§Arguments
  • key - The key to look up in the JSON object
§Returns
  • Some(f64) - The f64 value if found
  • None - If the key is missing or not an f64
§Example
let scale = args.get_opt_f64("scale");

Implementations on Foreign Types§

Source§

impl ArgsExt for Value

Source§

fn get_str(&self, key: &str, action: &str) -> Result<&str, AgentError>

Source§

fn get_opt_str(&self, key: &str) -> Option<&str>

Source§

fn get_u64(&self, key: &str, action: &str) -> Result<u64, AgentError>

Source§

fn get_opt_u64(&self, key: &str) -> Option<u64>

Source§

fn get_f64(&self, key: &str, action: &str) -> Result<f64, AgentError>

Source§

fn get_opt_f64(&self, key: &str) -> Option<f64>

Implementors§