Should end user utilities/applications be register

2019-04-09 05:06发布

问题:

Is it acceptable to register generally useful (utilities / applications) on crates.io?

The FAQ doesn't address this and from browsing, there are examples of end-user applications (mostly command line tools).

Or is crates.io? meant only for libraries?


I'm asking this because the documentation hints at library use, semantic versioning for API's etc. but doesn't reference the case for packaging applications explicitly.

回答1:

Yes, because you can use cargo install to install and manage those applications system-wide. If this use were discouraged, I would suspect that command to not exist at all, or at least have a very limited applicability.

Snippet from cargo install --help:

Usage:

 cargo install [options] [<crate>]
 cargo install [options] --list

[...]

This command manages Cargo's local set of installed binary crates. Only packages which have [[bin]] targets can be installed, and all binaries are installed into the installation root's bin folder. The installation root is determined, in order of precedence, by --root, $CARGO_INSTALL_ROOT, the install.root configuration key, and finally the home directory (which is either $CARGO_HOME if set or $HOME/.cargo by default).

There are multiple sources from which a crate can be installed. The default location is crates.io but the --git and --path flags can change this source. If the source contains more than one package (such as crates.io or a git repository with multiple crates) the <crate> argument is required to indicate which crate should be installed.



回答2:

This should not be the primary reason to publish an application to crates.io, but I'm listing it here because it's still a good reason. :)

The Rust team will occasionally use a tool called crater to check for regressions on all crates published on crates.io, usually before merging a pull request that has uncertain consequences. If you wrote some code that happens to compile today but would stop compiling1 due to a bug fix in the compiler, then they may even submit a pull request to your project that fixes your code!


1 Usually, when such breaking changes occur, there's at least one prior release in which a warning will be reported before the warning is turned into an error.