BobLoblaw
BobLoblaw

Reputation: 2001

crate name with hyphens not being recognized

I'm trying to practice rust using exercism

one of problem set has a test file like this enter image description here

when i tried to run Cargo test, its not recognizing the crate name.I tried different variations difference-of-squares,"difference-of-squares" with no success.enter image description here

contents of Cargo.toml

enter image description here

edit: I tried with both stable release and the current nightly.

Upvotes: 3

Views: 4362

Answers (2)

Robin
Robin

Reputation: 1736

With recent versions of Cargo, if your crate has a name with hyphens, you can directly rely on underscores instead. Cargo gives you this hint actually:

error: crate name using dashes are not valid in `extern crate` statements
 --> tests/config.rs:1:14
  |
1 | extern crate my-crate;
  |              ^^^^^^^^ dash-separated idents are not valid
  |
help: if the original crate name uses dashes you need to use underscores in the code
  |
1 | extern crate my_crate;
  |                ~

Upvotes: 0

DK.
DK.

Reputation: 59035

You're likely using an old version of Cargo. Previously, crates-with-hyphens were allowed, but horrible to use:

extern crate "difference-of-squares" as squares;

At some point in the past, Cargo was changed to basically not allow them; it just converted all hyphens to underscores so you didn't have to manually rename every crate that had hyphens in its name, every time you used it.

You haven't specified what version you're using, but updating to the latest release (Rust 1.2 just got released will be released in a few days) should fix it. Failing that, try quoting the literal name of the crate.

Upvotes: 10

Related Questions