Crate cairo_args_runner
source ·Expand description
§Cairo Args Runner
cairo_args_runner
is a utility designed to execute Cairo 1 programs with arguments directly from the command line.
This tool simplifies the process of running Cairo programs by allowing you to specify arguments directly in the command line.
§Configuration
Make sure your Scarb.toml
file includes the following section:
[lib]
sierra-text = true
§Examples
§Running a Complex Function
Run a complex function with an array of arguments:
use cairo_args_runner::{arg_array, felt_vec, run};
let target = "target/dev/complex.sierra.json";
let function = "main";
let args = vec![arg_array![1, 2, 4, 8, 16], arg_array![1, 2, 3, 4, 5, 6]];
let result = run(target, function, &args);
assert_eq!(result.unwrap(), felt_vec![31, 21, 5, 6]);
Note: There is a known bug in this example related to passing arrays as arguments. For more details and updates on this issue, please visit Issue #7 on GitHub.
§Fibonacci Sequence
Calculate the 10th number in the Fibonacci sequence:
use cairo_args_runner::{arg_value_vec, felt_vec, run};
let target = "target/dev/fib.sierra.json";
let function = "main";
let args = arg_value_vec![10];
let result = run(target, function, &args);
assert_eq!(result.unwrap(), felt_vec![55]);
§Working with Structs
Execute a function that works with multiple struct arguments:
use cairo_args_runner::{arg_array, arg_value_vec, felt_vec, run};
let target = "target/dev/structs.sierra.json";
let function = "main";
let mut args = arg_value_vec![1, 2, 10, 5, 9];
args.push(arg_array![1, 2, 3]);
let result = run(target, function, &args);
assert_eq!(result.unwrap(), felt_vec![33]);
§Summation Example
Run a function to sum an array of numbers:
use cairo_args_runner::{arg_array, felt_vec, run};
let target = "target/dev/sum.sierra.json";
let function = "main";
let args = vec![arg_array![1, 3, 9, 27]];
let result = run(target, function, &args);
assert_eq!(result.unwrap(), felt_vec![40]);
These examples demonstrate various ways to use cairo_args_runner
to execute Cairo 1 programs with different types of arguments,
aiding users in understanding and utilizing the utility effectively.
Modules§
Macros§
Structs§
VecArg
is a wrapper around a vector ofArg
.
Enums§
- An argument to a sierra function run,
Functions§
- Runs the specified function with the provided arguments.