Skip to content

Suggest standard-library replacements on crate pages#13855

Open
Turbo87 wants to merge 5 commits into
rust-lang:mainfrom
Turbo87:native-replacements
Open

Suggest standard-library replacements on crate pages#13855
Turbo87 wants to merge 5 commits into
rust-lang:mainfrom
Turbo87:native-replacements

Conversation

@Turbo87
Copy link
Copy Markdown
Member

@Turbo87 Turbo87 commented Jun 4, 2026

When a crate's functionality is now available in the standard library, this shows a banner on the crate page and a small marker in dependency lists, each pointing the reader at the relevant std API. The suggestion is deliberately limited to the standard library and never compares third-party crates against each other, so every entry stays a checkable factual statement about std rather than an opinion.

The data lives in a curated module at svelte/src/lib/data/native-replacements.ts, which maps a crate name to one or more std targets. Each target records the Rust version that stabilized it and a documentation URL, and each entry carries a flag for whether std covers the crate fully or only its common case, alongside a short curated description. It ships seeded with lazy_static, once_cell, matches, and num_cpus. The rules for what qualifies sit right next to the data as a module-level doc comment, covering the limited scope, the bar for full and partial entries, and a step where the maintainer of a flagged crate can weigh in before the entry lands.

The banner appears on the crate page for every version of a flagged crate, and the dependency list shows a marker whose tooltip carries the same description and links straight to the std item. Both surfaces are visible in the NativeReplacementBanner and dependency-list/Row Storybook stories, and they are covered by component tests and end-to-end tests for the present and absent cases.

Crate page screenshot

grafik

Dependency list screenshot

grafik

Related

@Turbo87 Turbo87 added the C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works label Jun 4, 2026
Comment on lines +1 to +40
/**
* Native replacement policy
* =========================
*
* This dataset flags crates whose functionality has been absorbed into the
* Rust standard library, so a reader can see that `std` now provides what the
* crate offers. Every entry is a checkable factual statement about `std`, never
* an editorial judgement about a competing third-party crate.
*
* Scope
* -----
* Standard-library supersession only. The set deliberately does not include
* "prefer this nicer crate instead" style recommendations.
*
* Inclusion criteria
* ------------------
* Two kinds of entries qualify:
*
* - Full (`full: true`): the crate's functionality is entirely available via
* a stable `std` API.
* - Partial (`full: false`): the bulk of the crate's common use case has
* moved to `std`, but not all of it. The `description` must spell out what
* is still missing.
*
* Coverage is judged roughly, and only the dominant use case counts. If just a
* small slice of a crate's purpose lives in `std`, it does not qualify, since
* flagging it would be misleading and noisy. `itertools` is the canonical
* exclusion: a few adaptors have `std` equivalents, but the crate is
* overwhelmingly not superseded.
*
* Every entry must cite the stable `std` API(s) and the Rust version(s) that
* stabilized them via the `targets` field.
*
* Maintainer notice-and-comment
* -----------------------------
* Entries should arrive as PRs judged against the criteria above. Before an entry
* lands, the maintainer(s) of the crate being flagged get a window to weigh in,
* either to object or to show that supersession is less complete than claimed,
* in which case the entry becomes partial or is rejected.
*/
Copy link
Copy Markdown
Member Author

@Turbo87 Turbo87 Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included a basic policy on what replacements should be added to the list.

View changes since the review

}

/** Keyed by exact crate name for O(1) lookup. */
export const nativeReplacements: Record<string, NativeReplacement> = {
Copy link
Copy Markdown
Member Author

@Turbo87 Turbo87 Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contains a basic first set of replacements. I hope I characterized them correctly. Let me know if you find any mistakes!

View changes since the review

@Turbo87 Turbo87 requested a review from a team June 4, 2026 17:06
Comment on lines +111 to +132
targets: [
{
path: 'std::sync::OnceLock',
stabilizedIn: '1.70.0',
url: 'https://doc.rust-lang.org/std/sync/struct.OnceLock.html',
},
{
path: 'std::cell::OnceCell',
stabilizedIn: '1.70.0',
url: 'https://doc.rust-lang.org/std/cell/struct.OnceCell.html',
},
{
path: 'std::sync::LazyLock',
stabilizedIn: '1.80.0',
url: 'https://doc.rust-lang.org/std/sync/struct.LazyLock.html',
},
{
path: 'std::cell::LazyCell',
stabilizedIn: '1.80.0',
url: 'https://doc.rust-lang.org/std/cell/struct.LazyCell.html',
},
],
Copy link
Copy Markdown
Member Author

@Turbo87 Turbo87 Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this kind of structured data is actually needed for our first implementation, since we only use description and url anyway 🤔

View changes since the review

@LawnGnome
Copy link
Copy Markdown
Contributor

I'd like to talk about this at tomorrow's meeting. (Or on Zulip, but since we have a meeting tomorrow anyway, let's start there.)

@Turbo87 Turbo87 force-pushed the native-replacements branch from 33e0e9a to aa894de Compare June 5, 2026 06:31
@rustbot

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@LawnGnome LawnGnome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues on the code.

If we're showing a tooltip on dep rows, should we also be showing a tooltip on search results?

View changes since this review

@Turbo87
Copy link
Copy Markdown
Member Author

Turbo87 commented Jun 5, 2026

If we're showing a tooltip on dep rows, should we also be showing a tooltip on search results?

I'm having a hard time expressing it properly, but I think the goals and target audiences are slightly different between these

Turbo87 added 5 commits June 5, 2026 18:36
Introduce `svelte/src/lib/data/native-replacements.ts` with the
`StdReplacementTarget` and `NativeReplacement` types and a seeded
`nativeReplacements` record mapping crate names to their std supersession.
Add a module-level doc comment capturing scope, inclusion criteria, and
the maintainer notice-and-comment step that governs entries in the
`nativeReplacements` record.
Render a crate's std-supersession entry as a banner: the curated HTML
description and a "Learn more" link resolved via `primaryUrl()`. Includes a
Storybook story and component tests.
Look up the viewed crate in `nativeReplacements` and, when present, show the
banner above the crate contents. Add e2e coverage for the present and absent
cases.
Show a marker linking to the std replacement next to any dependency present
in `nativeReplacements`, with a tooltip carrying the description and an
accessible label. Cover the present and absent cases in unit and e2e tests.
@Turbo87 Turbo87 force-pushed the native-replacements branch from aa894de to 6f8d9b3 Compare June 5, 2026 16:37
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 5, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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

Labels

A-frontend 🐹 A-svelte C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works

Projects

Status: For next meeting

Development

Successfully merging this pull request may close these issues.

3 participants