How to specify the path to Cargo.toml

I am new to Rust and I want to create and run my project. I am using something like:

cd %project_path% cargo run 

I want to write cargo run -path %project_path% on one line because I want to create a script assembly that does not allow changing the working directory. It seems that the cargo does not have any -path or -path keys that would define the target directory, and I always get the message

could not find Cargo.toml in C:\WINDOWS\system32 or any parent directory

+5
source share
1 answer

The --manifest-path path/to/Cargo.toml for almost all cargo subcommands allows you to specify its specific Cargo.toml file for use, overriding the default value for searching in the current directory and its parents for a file named Cargo.toml (this manifest file).

By the way, unix-y commands usually accept the -h or --help argument, which prints information about their command line options, cargo and rustc are no exception. For instance.

 $ cargo run --help Run the main binary of the local package (src/main.rs) Usage: cargo run [options] [--] [<args>...] Options: -h, --help Print this message --bin NAME Name of the bin target to run --example NAME Name of the example target to run -j N, --jobs N The number of jobs to run in parallel --release Build artifacts in release mode, with optimizations --features FEATURES Space-separated list of features to also build --no-default-features Do not build the `default` feature --target TRIPLE Build for the target triple --manifest-path PATH Path to the manifest to execute -v, --verbose Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never If neither `--bin` nor `--example` are given, then if the project only has one bin target it will be run. Otherwise `--bin` specifies the bin target to run, and `--example` specifies the example target to run. At most one of `--bin` or `--example` can be provided. All of the trailing arguments are passed to the binary to run. If you're passing arguments to both Cargo and the binary, the ones after `--` go to the binary, 
+10
source

Source: https://habr.com/ru/post/1241922/


All Articles