this post was submitted on 14 Aug 2023
28 points (96.7% liked)

Rust

6005 readers
5 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

I have a written a bit of rust by now, but one problem I always seem to encounter it that the features a create supports never seem to be documented. Neither what features are available, what they each do or which are default. Is that really the case, or am I missing something?

I constantly seem to include something from the docs, only to be told by the compiler that it does not exist, and then I have to open the source for the create to figure out if it's hidden behind a feature flag.

Also, is it really true that I can't disable a single feature from the default set, without having to copy the default list and manually removing it?

you are viewing a single comment's thread
view the rest of the comments
[–] RunAwayFrog@sh.itjust.works 6 points 1 year ago (6 children)

I constantly seem to include something from the docs, only to be told by the compiler that it does not exist, and then I have to open the source for the create to figure out if it’s hidden behind a feature flag.

As others mentioned, the situation is not perfect. And you may need to check Cargo.toml. Maybe even the source.

But as for the quoted part above, the docs should definitely indicate if a part of the API is behind a feature. Let's take rustix as an example.

Here is the module list:

Here is the view from inside a module:

Here is the view from a function page:

This is also true for platform support. Take this extension trait from std:

Now, it's true that one could be navigating to method docs in the middle of a long doc page, where those indicators at the top may be missed. But that's a UI issue. And it could be argued that repeating those indicators over and over would introduce too much clutter.

[–] pileghoff@programming.dev 4 points 1 year ago (5 children)

Is that always suppose to be shown? My counter example (the one that prompted this thread) is embassy_executor::Executor. When looking in the docs i dont see anywhere that its locked behind a feature flag, you have to look in the source

[–] RunAwayFrog@sh.itjust.works 5 points 1 year ago (4 children)

So, this is being worked on. But for now, that crate needs this line in lib.rs

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

And this line in Cargo.toml's [package.metadata.docs.rs] section:

rustdoc-args = ["--cfg", "docsrs"]

With these changes, feature gating will be displayed in the docs.

To replicate this locally:

RUSTDOCFLAGS='--cfg docsrs' cargo doc --features=nightly,defmt,pender-callback,arch-cortex-m,executor-thread,executor-interrupt
[–] snaggen@programming.dev 1 points 1 year ago (1 children)

Didn't know about this, looking forward for this to be stabilized. But a comment on your command, it is easier to use --all-features instead of listing them all.

[–] RunAwayFrog@sh.itjust.works 1 points 1 year ago* (last edited 1 year ago)

--all-features doesn't work with that particular crate because two of the features conflict with each other. The features list in my command is the one used for docs.rs from the crate's Cargo.toml.

load more comments (2 replies)
load more comments (2 replies)
load more comments (2 replies)