Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API documentation front page styleguide #1687

Closed

Conversation

Projects
None yet
@jonathandturner
Copy link
Contributor

jonathandturner commented Jul 25, 2016

This adds a proposal for the API documentation front page (the front matter you see when you first look at a crate's documentation). This is intended specifically for rust-lang crates, but works as suggested guidelines for any crate authors.

@BurntSushi

This comment has been minimized.

Copy link
Member

BurntSushi commented Jul 25, 2016

>
> If no logging implementation is selected, the facade falls back to a "noop" implementation
> that ignores all log messages. The overhead in this case is very small - just an integer load,
> comparison and jump. > > A log request consists of a target, a level, and a body. A target

This comment has been minimized.

@sfackler

sfackler Jul 25, 2016

Member

A couple newlines got chomped here.


* A concise explanation of the crate's purpose.
* The summary describes how the crate behaves in 3 short paragraphs.
* Even if you don't want to read the rest of the `README`, you have enough to get started.

This comment has been minimized.

@sfackler

sfackler Jul 25, 2016

Member

README or rustdoc?

This comment has been minimized.

@nagisa

nagisa Jul 26, 2016

Contributor

I always find myself copying the description from the crate-level introduction to README. Something that we could work on abstracting.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 25, 2016

I think @sfackler's comment here is actually an interesting one when taken more broadly as well. In terms of the "front page" of a crate, should we conventionally put more efforts into READMEs or crate documentation?

A README tends to actually be the first thing you read when hitting a crate (e.g. looking at the source on GitHub), and only afterwards might you go look at the documentation. That being said I'd personally prefer to put all documentation into the crate as it reduces duplication and it should "live with the code". Perhaps though discussion about this may be appropriate for this RFC?


This RFC is a companion to the [API doc guidelines proposal]
(https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md).
In this RFC, we focus on the format and style of the "front page" of an API. The goal of this

This comment has been minimized.

@nagisa

nagisa Jul 26, 2016

Contributor

You mean front page of documentation as generated by rustdoc? “API” is a function or a set of functions exposed to other programmers and the acronym is in no way related to presentation.

What do we mean by "no jargon is introduced in the first few paragraphs"? Using the `rand` crate as
an example - the crate's initial documentation probably should _not_ include a discussion of
cryptographically secure random number generators since its primary purpose, for most Rust
developers, will be to produce any random number. This information should instead be provided in a

This comment has been minimized.

@nagisa

nagisa Jul 26, 2016

Contributor

primary purpose, for most Rust developers, will be to produce any random number

That is a great misconception. It is very easy to incorrectly decide on a random number generator for pretty much all the use cases without taking in account the cryptosafety of the generator and the need for it. Even the trivial die-rolling games are flawed without a crypto-safe generator in some circumstances.

That being said, I do agree that discussion about generator’s crypto-safety should be elsewhere (such as the generators themselves)


Let's look at a sample of a good first example of a crate. Notice that the author has focused on
getting started, showing how to import and use the crate, and a few simple uses of common
functionality.

This comment has been minimized.

@nagisa

nagisa Jul 26, 2016

Contributor

Lately I’ve begun to also include a snippet that may be copy-pasted into a Cargo.toml (reasons in next paragraph). I’d suggest including that into this recommendation as well.

I do so, because the first thing I check out about the crate is its documentation. Seeing something like

//! ```toml
//! [build-dependencies]
//! gcc = "0.3"
//! ```

saves me the effort of:

  • remembering the crate name (e.g. crate is gcc, repository is gcc-rs; causes confusion);
  • figuring out what the latest version is;
  • what section I am supposed to put the dependency into;

The last point is esp. important when adding a dependency to a project which had no dependencies before, or adding the dependency in non-trivial ways (say with some features enabled/disabled) – I have trouble remembering how to do those things all the time.


Basically my first example becomes a Usage instead with step-by-step instructions on how to use a crate beginning with getting it into your cargo project.

This comment has been minimized.

@frewsxcv

frewsxcv Dec 15, 2016

Member

saves me the effort of:

  • figuring out what the latest version is;

From what I've witnessed, It is very common for library maintainers to forget to bump this number in the documentation, which I think is a worse user-experience than just not mentioning it at all.

That said, when it is the correct version number, I do find the section helpful. So I'm pretty neutral on this.

@mdinger

This comment has been minimized.

Copy link
Contributor

mdinger commented Jul 26, 2016

When someone links to the docs, there often isn't a link back to the repo or the crate which isn't really nice. This can be manually added but often isn't. It could be added as a convention.

Alternatively, maybe a shield could be added for the crate and repository or something. It seems like something which would probably be easy to include in rustdoc (not quite sure but it seems like it).

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Jul 26, 2016

When someone links to the docs, there often isn't a link back to the repo or the crate which isn't really nice. This can be manually added but often isn't. It could be added as a convention.

If we make that a convention or shield, could we do the same for a link to crates.io, I also often want that from a docs page.

@nrc nrc added the T-libs label Jul 26, 2016

@mdinger

This comment has been minimized.

Copy link
Contributor

mdinger commented Jul 27, 2016

That's actually what I meant by crate but yeah, that'd be cool.

## Introduction text to the crate

The first thing potential users of your crates will see is the introductory summary. This section is
a good place to introduce the what and the why the crate. A good introduction is concise but also

This comment has been minimized.

@jbcden

jbcden Jul 27, 2016

s/why the/why of the

@GuillaumeGomez

This comment has been minimized.

Copy link
Member

GuillaumeGomez commented Jul 27, 2016

About the README overlaps, IMO, it's normal. The only differences should be:

  • Dependencies of the crate.
  • How to build this crate.
  • Links to CIs status.

These things shouldn't be in the doc and should remain in the README file.

It's helpful to introduce and give a clear description for each capability separately to help your
readers understand each concept individually before they begin to combine capabilities.

Here's a good example from the 'rand' crate:

This comment has been minimized.

@jbcden

jbcden Jul 27, 2016

s/'rand'/rand

This comment has been minimized.

@jbcden

jbcden Jul 27, 2016

I wonder if this should be a link. When mentioning the log crate above you make it a link. I don't think a link has been provided for rand yet despite multiple mentions.

## Capability Examples

Sample code for each crate capability should be as simple as possible and side effect free. In the
rand crate, thread safe RNG is demonstrated 5 lines of code:

This comment has been minimized.

@jbcden

jbcden Jul 27, 2016

s/rand/rand or a link?

This comment has been minimized.

@jbcden

jbcden Jul 27, 2016

s/demonstrated 5/demonstrated in 5

@Havvy

This comment has been minimized.

Copy link
Contributor

Havvy commented Aug 5, 2016

Do these guidelines actually necessitate changing any crates to match the guidelines?

@alexcrichton alexcrichton added T-doc and removed T-libs labels Aug 15, 2016

peschkaj and others added some commits Aug 19, 2016

Cleans up links and formatting.
* Corrects typos in RFC.
* Normalizes use of `rand` instead of rand.
@matklad

This comment has been minimized.

Copy link
Member

matklad commented Aug 29, 2016

I also find it useful when a landing page of the API docs contains links to source code repository and the crates.iopackage.

Right now, for example, it is impossible to discover github repository of the log using only https://doc.rust-lang.org/log/log/index.html.

@frewsxcv

This comment has been minimized.

Copy link
Member

frewsxcv commented Dec 15, 2016

I also find it useful when a landing page of the API docs contains links to source code repository and the crates.io package.

I also see the value in adding a link to the source repository from the API documentation. This is tangential, but couldn't this be done automatically by retrieving the repository value in 'Cargo.toml' and putting somewhere in the generated documentation?

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Jan 31, 2017

Ping on this RFC -- what's the status?

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Jan 31, 2017

@aturon aturon referenced this pull request Jan 31, 2017

Open

Rust should provide easy access to high quality crates #9

5 of 11 tasks complete
@jonathandturner

This comment has been minimized.

Copy link
Contributor Author

jonathandturner commented Jan 31, 2017

@aturon - got distracted onto other things. I'll see if I can find the notes on what needed to be revised...

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Apr 26, 2017

@jonathandturner Checking in again on this -- relevant to the libs team work. cc @dtolnay as well.

dtolnay added some commits May 8, 2017

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented May 8, 2017

Hey @jonathandturner, could I get push access to your fork for the duration of this RFC? That way we can keep all the discussion in one PR.

@jonathandturner

This comment has been minimized.

Copy link
Contributor Author

jonathandturner commented May 8, 2017

@dtolnay - invited! BTW, feel free to pull me into discussions on it. I'm glad someone's taking this and running with it 😄

dtolnay added some commits May 8, 2017

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented May 8, 2017

I have updated the RFC to address the feedback so far and add my own experience. Rendered

  • I clarified the purpose of the introduction using an approach that I have found helpful in writing to-the-point introductions in the past. I think this concrete advice will be more valuable than something hand-wavy and obvious like "the what and the why of the crate."
  • I combined the capabilities and examples sections but with a note that examples may live under each capability or all together in an Examples section. In my experience neither of these approaches works well for every crate.
  • I would like this RFC to clarify the relationship between the rustdoc front page and the project's readme. I made a list of some things that have traditionally gone in the readme but not the front page doc, and some projects that have readmes/doc of varying levels of similarity.
  • I added lots of alternative ideas.
  • I added lots of unresolved questions.
@QuietMisdreavus

This comment has been minimized.

Copy link
Member

QuietMisdreavus commented Jun 5, 2017

So, when talking with the docs team about it, we generally like what's going on here, but we're not entirely sure how to address the unresolved question of what's actually different between a crate's front matter and its README.

I'll just add my own experience here. Here's what I put in a README that doesn't necessarily go in the front matter, in addition to the items already listed:

  • "How to add this library to your project" boilerplate. Each crate I have that's published, I have a little toml blurb and extern crate line in the README that shows how to add that crate to a rust project. I leave these out of the generated documentation, though, because in the context of "what does this library do" those lines are just noise.
  • Description of the examples/ directory, or anything specific to the layout of the repository itself. I may link to the repository from the crate-root documentation, but I haven't actually said "In examples/tweet.rs you can see several of these methods being used" because I haven't wanted to create those links in a place that's likely to grow stale if I update the example code or the layout of that directory itself.

If I were to apply a generalization to these things and the things already listed in the RFC, I might consider "Things that apply solely or primarily to the source code or the layout of the repo belong in the README." The "how to use this" boilerplate would fall under an additional "background knowledge" provision, since I personally would consider that knowledge to be out of scope for the a specific library's documentation.

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Sep 6, 2017

Bump on this -- can we drive to a resolution?

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 6, 2017

I am going to re-read this and related RFCs soon; some of the other ones may change the way this RFC should work, especially things like #1990

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Sep 6, 2017

I don't think I have bandwidth for this in the next 2 weeks before the impl period.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 6, 2017

@dtolnay is postponing maybe the right choice then?

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 6, 2017

@rfcbot postpone

Given @dtolnay 's comment above, and that this would need revisions based on other non-accepted RFCs, I suggest we postpone this till next year.

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Sep 6, 2017

@rfcbot fcp postpone

1 similar comment
@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 6, 2017

@rfcbot fcp postpone

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Sep 6, 2017

Team member @steveklabnik has proposed to postpone this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 6, 2017

Checking off @jonathandturner since he's not on the team anymore; should update @rfcbot !

@QuietMisdreavus

This comment has been minimized.

Copy link
Member

QuietMisdreavus commented Sep 7, 2017

@rfcbot reviewed

1 similar comment
@frewsxcv

This comment has been minimized.

Copy link
Member

frewsxcv commented Sep 7, 2017

@rfcbot reviewed

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Sep 20, 2017

I'm going to go ahead and close this out as postponed, since the impl period has started. Thanks all!

@aturon aturon closed this Sep 20, 2017

@kbknapp kbknapp referenced this pull request Dec 7, 2017

Open

1.0 Release #16

15 of 57 tasks complete

@kbknapp kbknapp referenced this pull request May 9, 2017

Open

Lib Blitz Style Summary and Overhaul #950

15 of 62 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.