Search code examples
rustmacrosrust-proc-macros

What is proc_macro2 vs. proc-macro2?


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?


Solution

  • 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.