1

Trying to learn procedural macros as part of internalizing Rust. I don't need competing crates. What is going on here?

proc-macro2:

https://crates.io/crates/proc-macro2

proc_macro2:

https://docs.rs/proc-macro2/latest/proc_macro2/

WTH is going on here? It's causing all sorts of issue trying to run "cargo upgrade" and somehow get cargo.toml and main.rs to agree on underscore vs dash. Seems very silly, what am I missing?

Ken White
  • 123,280
  • 14
  • 225
  • 444
Andrew Voelkel
  • 513
  • 4
  • 10

1 Answers1

3

The crate name is with dash and that's how it needs to be specified in Cargo.toml.

But crate names with dashes become underscores for imports.

That's why docs.rs uses first dash - this is the crate name in crates.io - and second underscore - this is the crate name in Rust.

Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77
  • OK, got it. Is there a reason why there are two different standards? I get why there needs to be an underscore in Rust code, same reason as for C. But why have it be different for crate names? But thanks anyway, I was tired when I got to that barrier. – Andrew Voelkel Nov 08 '22 at 16:04
  • @AndrewVoelkel Why not allow dashes in crate names? – Chayim Friedman Nov 08 '22 at 16:14