Skip to content

Instantly share code, notes, and snippets.

@Andoryuuta
Last active March 11, 2023 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andoryuuta/35a95680e0965b3a089311ece675fcbc to your computer and use it in GitHub Desktop.
Save Andoryuuta/35a95680e0965b3a089311ece675fcbc to your computer and use it in GitHub Desktop.

Rust Pain Points

A personal list of pain-points, rough edges, ambiguities, etc observed while trying to work on Rust projects (+adject tooling, cargo, crates.io, rust-analyzer, etc). This list is for personal reference, of personal experiences, not for "dunking" on the language or for flame wars. Multiple things in this list might be entirely incorrect / just undocumented.

- vs _ in crate names

The most common pattern for crate names is to use hypens. However, hypens are not valid identifiers in Rust. As such, these get implicitly converted to underscores. If you have a crate named foobar-rs, all references to that package in Rust code will need to use foobar_rs.

At some point in the past, this was an explicit implementation detail, requiring the syntax: extern crate "foobar-rs" as foobar_rs;

However, this is now a magic (undocumented?) internal detail of Cargo, and is highly dependent on the crate type (bin, [dy|cy]lib), target OS, output file type (wasm, js, debug symbols), and more.

Additionally, in order to prevent crate typo squatting, a check is done at the crates.io package registry level which only allows a single - or _ package. (e.g. if foo-bar exists, one cannot create foo_bar).

References:

Features non-stablized for 5+ years

It is unfortune how common it is to google something Rust related to only find out that the answer is: This feature has existed as unstable/nightly for 5+ years, is widely used in various projects already and is de-facto stable, but is not marked as stable. You will need to ditch stable Rust to use this.

Invalid warnings for "unused" fields that are used.

If you make a struct tagged with #[derive(Debug)] and only use it for debug printing, then Rust will give you countless (invalid IMO) warnings claiming that the struct fields are never used. Despite the fact that they are used in a println! call.

The issue for this was closed with the general resolution being: just surpress the warnings with #[allow(unused)]. :/

rust-lang/rust#88900

warning: multiple fields are never read
  --> src\main.rs:8:5
   |
7  | struct MetalibHeader {
   |        ------------- fields in this struct
8  |     magic: u16,
   |     ^^^^^
9  |     build: u16,
   |     ^^^^^
10 |     platform_arch: u32,
   |     ^^^^^^^^^^^^^
13 |     size: i32,
   |     ^^^^
14 |
15 |     field_c: u32,
   |     ^^^^^^^
16 |     field_10: u32,
   |     ^^^^^^^^
17 |     field_14: u32,

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment