top | item 26814466

(no title)

TheGrassyKnoll | 4 years ago

Thanks for the code snippet, however (kind of a Rust newbie here)

  $ cargo install unicode_segmentation (chokes)

  $ cargo install unicode-segmentation (seems to work)

  and in Cargo.toml
  [dependencies]
  unicode-segmentation = "1.7.1" (seems to work)

  yet in the code, its:
  use unicode_segmentation::UnicodeSegmentation;

  Why couldn't they be consistent using a dash vs. an underscore ?

discuss

order

estebank|4 years ago

Identifiers in Rust can't have dashes (rustc will never rely on whitespace for proper tokenization). It is arguable that because of that crates should not have dashes in their name. cargo was changed to automatically convert dashes to underscores for convenience because some dislike underscores in names. I personally think this is an unnecessary source of confusion and now I would make all tools (mainly cargo) treat them interchangeably.

a1369209993|4 years ago

> rustc will never rely on whitespace for proper tokenization

Huh? That seems clearly untrue, eg `fnfoo` vs `fn foo` or `x && y` vs `x & &y` or `x<<shift_or_type > ::foo` vs `x < <shift_or_type>::foo`? Presumably for some or all of those, one version ends up being a error (eg bitwise and with a pointer from `x & &y` probably doesn't work), but that's not at the level of tokenization.

steveklabnik|4 years ago

You don’t cargo install libraries; the cargo.toml line is the right thing.

You can’t use -s in Rust identifiers, so they need to be normalized to _ to be referred to in code.

mvolfik|4 years ago

this is way too common in Python world too - packages (crates) use dashes (they look nicer?), but the packaged library is named with underscores, because `-` is math operation and can't be in a name