Suggest standard-library replacements on crate pages#13855
Conversation
| /** | ||
| * 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. | ||
| */ |
There was a problem hiding this comment.
I've included a basic policy on what replacements should be added to the list.
| } | ||
|
|
||
| /** Keyed by exact crate name for O(1) lookup. */ | ||
| export const nativeReplacements: Record<string, NativeReplacement> = { |
There was a problem hiding this comment.
This contains a basic first set of replacements. I hope I characterized them correctly. Let me know if you find any mistakes!
| 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', | ||
| }, | ||
| ], |
There was a problem hiding this comment.
I wonder if this kind of structured data is actually needed for our first implementation, since we only use description and url anyway 🤔
|
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.) |
33e0e9a to
aa894de
Compare
This comment has been minimized.
This comment has been minimized.
I'm having a hard time expressing it properly, but I think the goals and target audiences are slightly different between these |
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.
aa894de to
6f8d9b3
Compare
|
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. |
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
stdAPI. 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 aboutstdrather 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 morestdtargets. Each target records the Rust version that stabilized it and a documentation URL, and each entry carries a flag for whetherstdcovers the crate fully or only its common case, alongside a short curated description. It ships seeded withlazy_static,once_cell,matches, andnum_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
stditem. Both surfaces are visible in theNativeReplacementBanneranddependency-list/RowStorybook stories, and they are covered by component tests and end-to-end tests for the present and absent cases.Crate page screenshot
Dependency list screenshot
Related