I am coming from the world of node.js and npm where you can easily run "npm install blah" in an existing project to install the blah library. The cli tool figures out the latest version that will work, installs it, and automatically updates the package.json file.
When I just tried to run "cargo install dialogue" in a rust project I was kind of disappointed that cargo gave me this error:
error: there is nothing to install in `dialoguer v0.10.0`, because it has no binaries
`cargo install` is only for installing programs, and can't be used with libraries.
To use a library crate, add it as a dependency in a Cargo project instead.
Is there a reason why cargo purposely makes the user update cargo.toml by hand? Is there any flag or other command I can use to install a library easily similar to the npm way? Thanks!
There is a cargo sub-command for it called cargo edit. You can install it with cargo install cargo-edit. Then you can add packages like cargo add regex@0.1.41.
cargo install is specifically for installing executables into your system (ie. somewhere along $PATH) so they can be run from the command line. It is not for adding dependencies to your projects.