Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run examples of a rust project [duplicate]

1/ It happened to me run examples in this repo https://github.com/0xProject/OpenZKP

One of way to an example is

cargo run --release --example small_fib

I'm just curious why we can run the example small_fib at the root directory even the example small_fib is located in a subdir project as this repo consists of multiple projects.

2/ Another question is that the small_fib example was not specified in example section of the Cargo.toml but we can execute it with

cargo run --release --example small_fib
like image 396
user602874 Avatar asked Oct 16 '19 06:10

user602874


1 Answers

To answer your first question, the crypto/stark folder is added to the workspace section of the root's Cargo.toml. See the Cargo book about how this section works:

Whenever any crate in the workspace is compiled, output is placed in the workspace root (i.e., next to the root crate's Cargo.toml).

For your second question, the small_fib.rs file is placed in the examples folder of crypto/stark. It can be run directly as an example. I found this article to be very informative about Rust examples.

The important thing is that you don’t have to worry what to do with your example code anymore. All you need to do is drop it in the examples/ directory, and let Cargo do the rest.

like image 105
Sunreef Avatar answered Sep 21 '22 05:09

Sunreef