Rust playground with the top 10k crates

A "nice to have" feature would be to show the compiler version used when creating the shared code snippet. So that even if the snipper doesn't compile on the latest version of the compiler, it would still be possible to get it working locally.

How about (maybe a bit too much for now) storing the diffs of each edit ? This could give the possibility to "go back in time" and see / fork(clone into a new shared snippet) the original version / each edit individually.

One more thing regarding the sharing feature, would it be possible to add the possibility to create "private" (perhaps password protected) shared snippets ?

That's a good point. I'll consider adding "Save changes" button.

Yes users can specify the version manually.

What do you think of adding a pop up for the input field that can be opened with a short cut instead of displaying it all the time? I want to keep the interface as simple as possible.

|````````````````````````````````|````````````````|
| serde                          | Add dependency |
|................................|................|
1 Like

I doubt people would use snippet that only works with old dependencies.

If there're a lot of users that want it I'll consider implementing it. When deciding whether to add a feature or not, I ask my self "Will at least 10% of active users on any given day use this feature?"

Like on the official playground, I doubt that 1% of daily active users use Build, Test, ASM, LLVM IR, MIR, HIR, and WASM.

Big update:

  • Real-time output
  • ASCII Color support
  • Set [profile.dev] in the manifest block /* */
4 Likes

The home page no longer has a help link afaict.

Edit: Ohhh! The help still exists, but hidden in the menu... Except you can’t access that until you’re logged in. Maybe a separate “Help” button in the top bar might be a good idea?

Edit2: I remember a more helpful message being displayed when trying to run code without being logged in. The small popup that appears now and doesn’t give any explanation seems like it can make some (new) users angry. “Why do I have to log in” seems like a reasonable reaction.

Nice job! I must have missed it, but where is the source code for the playground itself located? I didn't see it on a quick skim here or in the help page.

Please let me know when you see this so I can address it.

I'll have to do a bit of Grafana to dig that up, but what I have easily available for the last 7 days:

12 Likes

Could you explain a little? What's the difference between "Evaluate" and "Execute", in particular?

Yes, it’s not necessarily the clearest. If I recall correctly…

Execute is what you expect, roughly equivalent to cargo run or cargo test.

Compile is close to cargo build. This covers Mir/llvmir/hir/assembly.

Evaluate is the legacy endpoint and is used by things like the rust docs or mdbook to execute code inline from other websites.

2 Likes

Thank you. Currently the repository is still private.

Also thank you for creating the official playground. It's such a big inspiration for this project. When I looked at the source code, I thought "Why stop at 100? Why not 10k?"

So I fetched a list of the top 10k crates, write a simple Dockerfile file that pre-compile the crates, and then ran docker build, and it finished in a few seconds.

That's easy.

No. I was naive. The output was full of "Version conflict", "Platform not supported", and "System library not found".

I thought the official playground must do some magic to precompile the top 100 crates.

Then I tried to precompile the crates one by one and skipped crates that failed. The compilation took very long, and many crates failed. The artifact also takes a lot of storage space, which makes it almost impossible to create the docker image. That made me gave up and stopped the project. After a few weeks I felt like I really need this[1]. I continued to exeperiment until I arrived at the current version.

Regarding slow docker run, I've tried running a single dedicated compiler container continuously so I don't have to run a new container on every "run". I compiled the code into wasm. With this architecture the start up time was much faster. But many crates won't compile to wasm. Not event rand.

[1] My initial motivation to create Rust Explorer was because my project at the time used many large dependencies. And the compilation took several minutes. My solution at the time was to create a repl package for writing small codes and then copy them to the main package. But it's very cumbersome to navigate between many repl packages.

2 Likes

I've been thinking about this lately. If visitors don't want to login to run code maybe they don't really need this service. Altering the interface to chase users that don't need RE could ruin the experience of those that need it. (That's what I heard startup gurus said).

I think login with Github is not a rare thing. We login every where on the internet. Even on this forum.

Also it'is not a startup. It's just a side project. I hope it could be useful for some Rust devs.

My main point was that the message could be more polite/friendly. It's very very terse right now, perhaps even rude depending on the context; plus it's the very first thing that almost any new visitors will experience. It doesn't hurt to add nicer wording.

"Welcome to rustexplorer.com. Please login first, if you want to run your own code here. [Learn more]" would be better than the bland "Login to run code". It could also e. g. be a tooltip on a greyed-out Run button instead of pretending there is a working run button and only erroring out afterwards. There also needs to be a way to learn more about what rustexplorer.com is in the first place. You can't blame users being hesitant to log in if they aren't familiar with the website at all yet.

Think of both scenarios: the new user that happens to land on the home page rustexplorer.com somehow, or the new user that got linked to a particular code example through a link that someone has shared. You don't need to try hard to convince them to log in, but you should try to avoid any bad and/or confusing initial user experience, too IMO. No need to scare someone away who would love to use the website if they knew what it was about.

3 Likes

I'm not sure how your or @shepmaster would feel about it, but there could be a button to try running it via the playground or to send you to a populated playground, especially if you could determine the playground has the required deps.

I guess you mean "run" button or embedding the playground on third party websites. You can embed the official playground using IFrame or send direct requests to the API end point. Though with Rust Explorer, CORS is not enabled on third party websites.

I just released a new update today. Now you can share a link to a URL-encoded bin. But the length of the code is limited by the max length of URL. Different browsers have different limit. So for longer code you should check the link first before you share it.

Here is an example [1].

Alternatively you can save the bin and share the (short) link.

[1] https://www.rustexplorer.com/b?code=%2F*%0A%5Bdependencies%5D%0Abencher%20%3D%20%22*%22%0A%0A%5Bprofile.dev%5D%0Aopt-level%20%3D%203%0A*%2F%0A%0A%23%5Bmacro_use%5D%0Aextern%20crate%20bencher%3B%0A%0Ause%20bencher%3A%3ABencher%3B%0A%0Afn%20a(bench%3A%20%26mut%20Bencher)%20%7B%0A%20%20%20%20bench.iter(%7C%7C%20%7B%0A%20%20%20%20%20%20%20%20(0..1000).fold(0%2C%20%7Cx%2C%20y%7C%20x%20%2B%20y)%0A%20%20%20%20%7D)%0A%7D%0A%0Afn%20b(bench%3A%20%26mut%20Bencher)%20%7B%0A%20%20%20%20const%20N%3A%20usize%20%3D%201024%3B%0A%20%20%20%20bench.iter(%7C%7C%20%7B%0A%20%20%20%20%20%20%20%20vec!%5B0u8%3B%20N%5D%0A%20%20%20%20%7D)%3B%0A%20%0A%20%20%20%20bench.bytes%20%3D%20N%20as%20u64%3B%0A%7D%0A%0Abenchmark_group!(benches%2C%20a%2C%20b)%3B%0Abenchmark_main!(benches)%3B

1 Like

Thank you for your feedback. That's a very good point.

Today I've released a new update and go with what you suggested. Please let me know what you think.

2 Likes

Lovely!

Hi, I’ve been using rust explorer some more today; it’s remarkable how even quite niche crates manage to make it into those top 10k!

A (hopefully fairly straightforward to implement) feature I’m missing a lot is a button to auto-format the code with rustfmt or cargo fmt. It’s such a common operation for me if I work in the playground, perhaps it would even make sense to offer it as an operation available through a single click (or keyboard shortcut) unlike the two-click approach in the playground (“Tools”->“Rustfmt”).

4 Likes

The back-end already supports cargo fmt, cargo expand, and clippy. Currently I'm rewriting the front-end, moving from React Router Dom to SvelteKit. There will be BIG update this week.

What do you think a good keyboard shortcut for cargo fmt, cargo expand, and clippy?

Do you expect cargo fmt to update the editor or print the result in the output section?

4 Likes

I would expect cargo fmt to update the editor. :slight_smile:


As for keyboard shortcut, I don’t know. I mean, I could tell you that what I’m most used to at the moment, from vscode on linux, is Ctrl+Shift+I; but that’s already used by the browser, I believe. On Windows, for vscode it’s Shift+Alt+F. But the choice really is quite arbitrary; most importantly, a keyboard shortcut is only useful if it’s discoverable through the UI; so the GUI option for cargo fmt should probably … somehow … include the hint as to what the keyboard shortcut is. Such a hint would also be useful for the “Run” functionality (currently Ctrl+Enter, AFAICT).

4 Likes