rust-lang / rust-lang/docs.rs

Enable playground for crates that are available there

Open
#1,508 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
232
Avg merge
11h 35m
Merged PRs (30d)
60

Description

When a crate is available in https://play.rust-lang.org we could add the --playground-url argument so that its examples get the "Run" button enabled. The list of crates currently supported is at https://play.rust-lang.org/meta/crates (@shepmaster are you ok if we use this url? (with appropriate fallback in case it changes)).

One small complication is crates that have multiple versions available:

    {
      "name": "ansi_term",
      "version": "0.12.1",
      "id": "ansi_term"
    },
    {
      "name": "ansi_term",
      "version": "0.11.0",
      "id": "ansi_term_0_11_0"
    },

the playground puts older versions under a renamed extern, so we wouldn't want to link them. This probably means we just need to do a lookup based on the id == lib_name and then semver comparison that it's within the same semver compatible range (in either direction, since docs will generally be built for a newer version before it gets deployed to the playground).

The bigger complication is that we would be making static data linking to dynamic data, crates come and go from the playground, and it updates their versions all the time. I think it's probably still worth it, from what I've seen the playground crate list changes slowly enough that I think the upside of having the button when it works will outweigh the times it doesn't.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how docs.rs examples receive the --playground-url setting and how the "Run" button is enabled. Use the playground /meta/crates data, including crate IDs and versions, to define the compatible-version lookup and fallback behavior. Done means supported crates link to the playground without linking older renamed versions, while unavailable or changed crates remain safe.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.