cpython::py_argparse! [] [src]

macro_rules! py_argparse {
    ($py:expr, $fname:expr, $args:expr, $kwargs:expr, ($( $pname:ident : $ptype:ty ),*) $body:block) => { ... };
}

This macro is used to parse a parameter list into a set of variables.

Syntax: py_argparse!(py, fname, args, kwargs, (parameter-list) { body })

  • py: the Python token
  • fname: expression of type Option<&str>: Name of the function used in error messages.
  • args: expression of type &PyTuple: The position arguments
  • kwargs: expression of type Option<&PyDict>: The named arguments
  • parameter-list: a comma-separated list of Rust parameter declarations (name: type). The types used must implement the ExtractPyObject trait.
  • body: expression of type PyResult<_>.

py_argparse!() expands to code that extracts values from args and kwargs and assigns them to the parameters. If the extraction is successful, py_argparse!() evaluates the body expression (where the extracted parameters are available) and returns the result value of the body expression. If extraction fails, py_argparse!() returns a failed PyResult without evaluating body.