Is it possible to publish only a library crate from the package?

If I have a library and binary crate in the package, can I only publish a library crate or can I publish both of them but as separate crates?, or will I have to create a new package?
Or if this is not possible, how will packages from the library and several binary crates be published?

Entire packages are published as a whole. Crates are never published except as components of packages.

It is common for projects to have two (or more) packages, one for the library and one for the binary. It's only necessary to do this if the binary has dependencies that you don't want to also be dependencies of the library; the presence of a binary does not mean that every dependent gets that binary installed.

Can you say more about the structure of your project and why you're considering splitting? That will help us tell you whether it's a good idea.

Thank you for your answer!!, I don't have a specific project, it's just interesting to know how this package will be considered as a library or as a binary when publishing in crates.io? And what it depends on if there is more than 1 crate in the package.

And if there is more than 1 binary crate in the package, then which will be installed via cargo install?

crates.io doesn't keep track; it just stores packages as long as they're valid.

(This actually causes some trouble; the sidebar will suggest cargo add <package> even if the package is only a binary. But there is nothing you can do about that, and someday it may be fixed.)

And if there is more than 1 binary crate in the package, then which will be installed via cargo install?

All of them at once. For an example, see cargo-edit.

Thank You!!,it explains all

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.