Is there anything Cargo can't do?

For a Rust developer, Cargo is an amazing utility. In addition to these common facilities, it also has other commands, which are listed in the table that follows. All commands follow this form:

cargo <command> <opts>  

Command

What it does

fetch

This command fetches the dependencies of a package from the network. If a lockfile is available, this command will ensure that all of the Git dependencies and/or registry dependencies are downloaded and locally available. The network is never called after a cargo fetch unless the lockfile changes.

If the lockfile is not available, then this is the equivalent of cargo generate-lockfile. A lockfile is generated and all the dependencies are also updated.

generate-lockfile

This command generates the lockfile for a project. The lockfile is typically generated when cargo build is issued (you will see it as Cargo.lockfile in the directory structure).

git-checkout

This command checks out a Git repository. You will need to use it in the following form:

cargo git-checkout -url=URL        
locate-project

This command locates a package.

login

This command saves an API token from the registry locally. The call is in the following form:

cargo login -host=HOST   token        
owner

This command manages the owners of a crate on the registry. This allows the ownership of a crate (a crate is a Rust library) to be altered (--add LOGIN or -remove LOGIN) as well as adding tokens to the crate.

This command will modify the owners for a package on the specified registry (or the default). Note that the owners of a package can upload new versions, yank old versions, and also modify the set of owners, so be cautious!

package

This command assembles the local package into a distributable tarball.

pkgid

This command prints a fully qualified package specification.

publish

This command uploads a package to the registry.

read-manifest

This command reads the manifest file (.toml).

rustc

This command compiles the complete package.

The specified target for the current package will be compiled along with all of its dependencies. The specified options will all be passed to the final compiler invocation, not any of the dependencies. Note that the compiler will still unconditionally receive arguments such as -L, --extern, and --crate-type, and the specified options will simply be added to the compiler invocation.

This command requires that only one target is being compiled. If more than one target is available for the current package, the filters --lib, --bin, and so on—must be used to select which target is compiled.

search

This command searches for packages at https://crates.io/.

update

This command updates dependencies as recorded in the local lockfile.

Typical options are:

  • --package SPEC (package to update)
  • --aggressive (forcibly update all dependencies of <name> as well)
  • --precise PRECISE (update a single dependency to exactly PRECISE)

This command requires that a Cargo.lock file already exists as generated by cargo build or related commands.

If a package spec name (SPEC) is given, then a conservative update of the lockfile will be performed. This means that only the dependency specified by SPEC will be updated. Its transitive dependencies will be updated only if SPEC cannot be updated without updating the dependencies. All other dependencies will remain locked at their currently recorded versions.

If PRECISE is specified, then --aggressive must not also be specified. The argument PRECISE is a string representing a precise revision that the package being updated should be updated to. For example, if the package comes from a Git repository, then PRECISE would be the exact revision that the repository should be updated to.

If SPEC is not given, then all the dependencies will be re-resolved and updated.

verify-project

This command ensures that the project is correctly created.

version

This command shows the version of Cargo.

yank

This command removes a pushed crate from the index.

The yank command removes a previously pushed crate version from the server's index. This command does not delete any data, and the crate will still be available for download via the registry's download link.

Note that existing crates locked to a yanked version will still be able to download the yanked version to use it. Cargo will, however, not allow any new crates to be locked to any yanked version.

 

As you can now appreciate, the Cargo utility script is extremely powerful and flexible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset