
Rust Playground - tosh
https://play.rust-lang.org/
======
stblack
The Rust playground is one of the many great things about Rust.

It's really helpful to share code and try concepts. The mere existence of the
playground is a catalyst to reduce and refine problems before airing them to
get help from the wider community.

Furthermore it's well integrated with the Rust community forums. The share
button functionality is brilliant.

A minor quibble: its state management is not particularly intuitive. There's
no notion of "save" or "branch" or versions as in Gists, for example. If there
is, I haven't found it. The playground URL appears to be a hash of its
contents? That's my guess. Does anybody know?

~~~
steveklabnik
Code is here: [https://github.com/integer32llc/rust-
playground](https://github.com/integer32llc/rust-playground)

> Does anybody know?

Yes, there's no branching for gists, but there are saves. If you hit "Share",
you get various options:

* Permalink to the playground <\- this creates a gist. URL is the gist hash.

* Direct link to the gist <\- this gives you a link to the gist

* Embedded code in link <\- this URLencodes the source and puts it in a parameter

* Open a new thread in the Rust user forum & Open an issue on the Rust GitHub repository <\- hopefully self-explanatory

------
dom96
I wonder why we're seeing this on HN's front page now. Did something change
recently in the playground?

~~~
ones_and_zeros
Kelsey Hightower tweeted about it.
[https://twitter.com/kelseyhightower/status/12812095507170713...](https://twitter.com/kelseyhightower/status/1281209550717071360)

~~~
xpe
I disagree with the tweet:

> The Rust playground is pretty dope. D*mn near a full blown IDE running in
> your browser ...

I am not a fan of exaggeration. No, it is not ‘near’ a full-blown IDE.

That said, I think the Playground is wonderful, especially for a compiled
language.

~~~
xpe
Here is a common list of features that comprise modern IDEs:

    
    
      - edit multiple files
      - search across files
      - console/terminal
      - debugging
      - customizable keyboard shortcuts
      - source control integration
      - extensions/plugins
    

Optional:

    
    
      - long startup times
      - complicated and overly nested settings
      - run-amok CPU-hogging plugins

~~~
Matthias247
This misses "having an understanding about the source code and associated
actions". Like refactoring helpers, autocompletion, etc. This is what
distinguishes an IDE from a text editor for me.

But anyway, the Rust playground has none of those anyway.

------
mcintyre1994
Something I really like about the Typescript playground is it has lots of
examples with documentation and, not to put too fine a point on it, they all
compile and run. Obviously this isn't designed for the same use case, but it'd
be nice (from my perspective!) to be able to load in some example code that
already works and doesn't produce an inscrutable (to a beginner) compile
error.

I'm sure this would be a great resource if I did start trying to learn the
language though, so thanks for sharing it :)

~~~
steveklabnik
Yeah, the relationship is a bit different. In Rust, we tend to have docs that
embed the playground or link to it, rather than having the playground link to
docs.

~~~
mkesper
Examples from the book shouldn't be too hard or at least some link to it?

~~~
steveklabnik
Sure. Here's a random page on the book: [https://doc.rust-
lang.org/stable/book/ch08-01-vectors.html](https://doc.rust-
lang.org/stable/book/ch08-01-vectors.html)

You can click the arrows to run the code. This effectively makes an AJAX call
to the playpen, and puts the results back on the page.

Here's a random page from the API docs: [https://doc.rust-
lang.org/stable/std/string/struct.String.ht...](https://doc.rust-
lang.org/stable/std/string/struct.String.html#examples)

Those "run" buttons will open up the example in the playpen so you can play
around with it.

I think ideally these would all let you edit in place, run in the page, or
open in the playpen, but they use slightly different tooling and nobody has
put in the work to make it all identical yet.

------
MR4D
Output of the default code in the app generates errors:

=================

    
    
       Compiling playground v0.0.1 (/playground)

error: unexpected token: `...` \--> src/main.rs:13:15 | 13 | for x in 0...10 {
| ^^^ | help: use `..` for an exclusive range | 13 | for x in 0..10 { | ^^
help: or `..=` for an inclusive range | 13 | for x in 0..=10 { | ^^^

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

------
rckoepke
I've wanted to turn some students onto Rust, so I tried to give them
[https://github.com/rust-lang/rustlings](https://github.com/rust-
lang/rustlings) loaded into a repl.it account -- but the way repl.it works
breaks rustlings in multiple ways.

I'd love if this Rust playground could eventually provide that experience.

------
miccah
I appreciate the vi mode editing. `:w` will compile and run the program, but
that is the only colon command I have discovered.

~~~
steveklabnik
It farms out this behavior to the Ace editor it uses. I'm not sure what all it
supports, but that's how you'd figure it out.

~~~
miccah
Thanks for the tip! If anyone is curious I found the list of commands here:
[https://github.com/ajaxorg/ace/blob/master/lib/ace/keyboard/...](https://github.com/ajaxorg/ace/blob/master/lib/ace/keyboard/vim.js#L1054-L1075)

------
secondcoming
Compiler Explorer lets you see the generated assembly code, if you're into
that sort of thing. Supports loads of languages and compilers too!

[https://godbolt.org/z/qM67Pe](https://godbolt.org/z/qM67Pe)

~~~
masklinn
Playground also provides that feature, but it doesn't clean the assembly as
well, nor does it provide side-by-side view and coloration.

Dropdown menu next to run, select "asm".

------
didip
Is there a way to browse what's in it? I'd like to see how people write Rust.

~~~
steveklabnik
There is not, mostly because nothing is “in it”; any persistent state is
farmed out to localstorage or gists, as far as I know.

------
prescojan
Usability significantly decreased - now you have to go into menus to do
anything. Yes, the interface may look cleaner, but you are not supposed to
admire playpen visuals, you are supposed to press those now hidden buttons
first of all.

~~~
wizzwizz4
I think the discoverability has increased, though. There are multiple ways to
"run" the code, all next to the "run" button (which will automatically change
to "test" if you put tests in your code), and compilation options are next to
that. Stuff like Clippy and Rustfmt is in the "tools" section.

------
aspaviento
Does it not work in incognito mode? the compiler reaches time out with the
println!("Hello, world!") example

Edit: reloading the page fixed it.

