13

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
user602874
  • 1,429
  • 2
  • 12
  • 10
  • I'd argue this question is not a duplicate of the other one. The title of the question is confusing but the OP is not asking how he can run an example but why it works in his case. – Sunreef Oct 17 '19 at 07:48

1 Answers1

11

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.

Sunreef
  • 4,452
  • 21
  • 33