Naming convention for crates #29
Replies: 17 comments 24 replies
-
I still think it shouldn't matter. rust-lang/cargo#2775 |
Beta Was this translation helpful? Give feedback.
-
Two things are being conflated here: crates and packages. A crate is the unit of compilation and that which you import into your code; its name must be a Rust identifier, and is conventionally unspecified, allowing it to determined automatically (from the package name with A package is the directory containing Cargo.toml, which could include a lib crate, multiple bin crates, examples, tests, &c. It is their naming convention that is unclear—though there are certain strong subconventions like *-sys. (The history of hyphens versus underscores is not particularly well documented; yet I say that kebab-case was the preferred convention the last time this was discussed; snake_case has gained in popularity because no declaration was made at that time of one particular form as preferred.) |
Beta Was this translation helpful? Give feedback.
-
This is confusing, I'm looking to run cargo new on a polar perlin noise loop... Well actually polar OpenSimplex noise loop. The loop is optional as I can't find /polar perlin noise .*/ that's not loop. What should I type, should I just make up some silly name or acronym so it's one word? |
Beta Was this translation helpful? Give feedback.
-
@cheako That’s not the type of naming convention that’s being spoken about here. You could call it polar-opensimplex-noise-loop if you wanted to if that’s not taken, or some other silly name, or whatever you like. What’s being talked about here is matters like whether you should use |
Beta Was this translation helpful? Give feedback.
-
I'm still confused. Should my new rust project use snake_case or kebab-case? |
Beta Was this translation helpful? Give feedback.
-
Personally, I have always, and continue to use, kebab case for crate names. |
Beta Was this translation helpful? Give feedback.
-
With reference the discussion had in r/rust/, Even though example:
To reduce confusions and to make docs and code more consistent, I think better promote And this issue is already 3 years old :) |
Beta Was this translation helpful? Give feedback.
-
Given that |
Beta Was this translation helpful? Give feedback.
-
A naming convention has already been accepted in RFC 430. The fact that it has not been followed is an issue. But, in my opinion, removing the convention altogether is not merited. |
Beta Was this translation helpful? Give feedback.
-
Could we clarify naming of procedural macro crates? Like |
Beta Was this translation helpful? Give feedback.
-
Semi-related to this discussion: it doesn't seem possible to change the separator once a crate has been published, which is unfortunate: rust-lang/crates.io#728 |
Beta Was this translation helpful? Give feedback.
-
Silver lining: using |
Beta Was this translation helpful? Give feedback.
-
We can use both.
it is fine to use both |
Beta Was this translation helpful? Give feedback.
-
I hate to add to a discussion that seems close to finalised, but when creating a new rust project, the folder name where the parent level Cargo.toml, src and target directories go, If so, should that be kebab or snake cased? The reason I ask is because when making a CLI tool in rust, when you run cargo build, you get an executable named whatever your package name is, which seems weird to be anything other than kebab-case (of course not all rust projects are CLI tools. just my two cents) |
Beta Was this translation helpful? Give feedback.
-
Correct. Packages are a cargo concept (see the Cargo Book Glossary). Sometimes the term "project" is used informally in documentation as well. The Rust language/compiler doesn't know about packages, only crates. In 2022, this issue is more than a bit confusing, because the title is "Naming convention for crates" but seems to be discussing the naming conventions for packages. RFC-0430 states that the naming convention for crates is As a complete Rust novice, it seems like the only sensible options for cargo package naming conventions is
I'd be very curious to see the data from crates.io on how many packages follow various candidate conventions, both in terms of raw counts and also by some reasonable measure of community popularity. Finally, FWIW the book is recommending snake_case for crates in its "Hello, Cargo!" example. |
Beta Was this translation helpful? Give feedback.
-
I arrived at this page from https://rust-lang.github.io/api-guidelines/naming.html#casing-conforms-to-rfc-430-c-case which still says [package]
name="my_lower_snake_case_package" # this is both the crate name and package name for basic rust projects |
Beta Was this translation helpful? Give feedback.
-
I'm probably not the right guy to do the whole dance as I have no idea, but how about this RFC sketch:
Steps to get there:
Or we may as well accept the status quo. It's not that bad, really. Just strange, considering how well defined everything else about Rust seems to be. |
Beta Was this translation helpful? Give feedback.
-
The current guideline says "
snake_case
(but prefer single word)." Is this still the case? Why do new high-profile crates liketokio-core
use kebab case?Beta Was this translation helpful? Give feedback.
All reactions