Skip to content

slice docs could use example functions, clear header #85950

Open
@workingjubilee

Description

@workingjubilee

The API docs for the slice type describes what [T] is and explains the meaning of &[T] and &mut [T], but this can still be vague for Rust programmers. A programmer with even a modest interest in using Rust for what it's been strongly advertised for, systems programming, is very likely to encounter the need to slice bytes between days 0 to 7, when they have not yet adjusted to Rust syntax and are not clear on why the type's identification in a function signature or type annotation is not the same as its name. In addition, it is easy to miss the type annotations in the existing examples.

Recently, on nightly, the struct declaration of e.g. std::vec::Vec has been made visible, making an easy to read "header" that quickly gives an example of the type. This is very nice for generated structs, especially ones with type parameters, but primitives have a harder time of it, as there's no obvious "declaration" to give to a reader. Instead, the problem to address is an immediate "okay, what does this look like in usage?" So, a clear example of a very simple function signature as one of the visible examples, and possibly raising the descriptions of &[T] and &mut [T] towards the top of the page, may help clarify this.

Reproducer

We tried the documentation page for the slice type.
We expected to see an easy-to-read example of a function that accepts or returns slices.
Instead, we scanned the page without finding a clear example of such, and found it easy to miss the existing examples.
May require being mildly tired or undercaffeinated to reproduce.

Docs Version

# at the time of this issue, this could use improvement for both the stable and nightly std API docs
rustc 1.54.0-nightly (9111b8ae9 2021-05-26)
rustc 1.52.1 (9bc8c42bb 2021-05-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-sliceArea: `[T]`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions