-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
An annoying papercut with Rust is crate names containing hyphens, e.g. aho-carosick.
It has been a number of years since I learned this, but at some point I knew that you accessed crate members based on the crate name:
use crate_name::foo;
but I did not know that crate names with hyphens were automatically converted to underscores. I know it sounds obvious if you already know it, but really - this is not obvious, nor is it easy to search for a solution.
Even worse if lib.name
is set (see also #6827)
I think Cargo (and crates.io, but I guess that's out of scope here) could do more to help:
Proposed Solution
When you create a new crate viacargo init
with a crate name containing hyphens, warn that it may be confusing to new users because the crate name doesn't match the crate name. This could be a one-time or few-time warning, so as not to annoy people. See also Ask for confirmation of certain crate data on first publish #8883- When you
cargo add aho-carosick
, note that you will need to useaho_carosick
in code. Ditto on few-time warnings. Currently it actually warns in the opposite direction which is kind of silly:warning: translating regex_syntax to regex-syntax
. crates.io should list the command ascargo add aho_carosick
notcargo add aho-carosick
. Both work but the former makes it more obvious how to use the code.
It's going to be really easy for seasoned Rust developers (including me, now) to dismiss this as trivial and obvious. Trust me it wasn't when I was learning, and I'm sure it isn't for many other people.