
Rust Playground - dolftax
http://play.rust-lang.org/
======
Intermernet
Yay! I'll just mention that this one feature will help this language
immensely. The standard method for sharing Go code snippets is on
play.golang.org, and the huge number of JS/HTML/CSS sandboxes out there have
shown that an online, linkable code execution environment can really help with
language adoption.

What are the limitations of the online environment vs the full language? (I
presume a lot of low level stuff is sand-boxed or mocked) What features _aren
't_ available?

~~~
ben0x539
The biggest limitation is probably that you can't use packages from the cargo
ecosystem.

I haven't looked in detail but afaik it runs genuine rust binaries in a
sandbox. You can investigate at [https://github.com/rust-lang/rust-
playpen](https://github.com/rust-lang/rust-playpen) /
[https://github.com/thestinger/playpen](https://github.com/thestinger/playpen)
if you feel like it. :P

------
rattray
The gist feature is great. They seem to have thought this through well without
adding too many bells & whistles. (though I do find the url animation when you
create a shortened/gist url unnecessary)

------
S4M
It's really nicely done, but I would love it even more if they could add some
more examples, like in Golang's "Try Go" [0].

[0] [http://golang.org/](http://golang.org/)

~~~
mbrubeck
Related tip: If you click the arrow that appears when hovering over any of the
example code in the Rust book [1] or other Rust documentation, it will open
the example in the playpen.

[1]: [http://doc.rust-lang.org/book/](http://doc.rust-lang.org/book/)

------
pshc
IR output is too cool. It's really nice of LLVM to let you use arbitrary
strings in identifiers, like

    
    
      %"2.core::fmt::rt::v1::Position"
    
      %"2.core::option::Option<&'static [core::fmt::rt::v1::Argument]>"
    

makes it easy to understand.

------
peferron
I've been using the Rust playground a lot this week, and I wish it had a
history feature - I often closed a tab and later wished I could get the code
back.

I'm thinking about trying to contribute a localStorage-based history
mechanism. Does anyone else think it'd be a good addition? And if so, any
suggestions regarding the behavior?

~~~
MJSplot_author
I think I would be good. They are using the ace text editor, so something
simple like:

on pageload: var t = localStorage.getItem("textbackup"); if (t){
__editor.setValue(t); console.log('restoring from backup'); } else {
__editor.setValue(document.getElementById('basic_intro').innerHTML);
console.log('putting in the intro'); }

and on any action: var text = __editor.getValue();
localStorage.setItem('textbackup', text);

It's the approach I've taken in my version a playground for a different
program.
[http://xqt2.com/mjslab/mjslab.html](http://xqt2.com/mjslab/mjslab.html)

~~~
peferron
That's definitely useful, but the current Rust playground already does this
(sorry for not being clear in my post). I meant a more full-featured history
where you can view multiple previous edits, not just restore the last one.

------
IshKebab
This editor has interesting tab behaviour. It uses spaces, but some more
actions than usual make it act like tabs.

Specifically, if you press tab (insert 4 spaces) and then the left arrow, it
actually jumps left 4 spaces instead of 1.

Unfortunately it doesn't fully behave like tabs because you can still click
inside the indentation which makes selection and cursor positioning harder.

~~~
ewillbefull
Rust convention is for 4-space indentation, not tabs. In fact, in the
compiler's own code tabbed indentation fails tests. The way the playpen works
is a "best of both worlds" approach I guess.

------
contradictioned
It has multicursor support. Press Ctrl + Click :)

~~~
fit2rule
Doesn't work on OSX, but: cool anyway. Every editor needs multi-cursor
support.

~~~
zeen
Cmd + Click on OS X, as it should be.

------
ancarda
I don't know a lot about compilers or assembly but the ASM output seems a
longer than it needs to be for just printing hello world. Can anyone provide
some insight? Is it just long to provide a good foundation for bigger
programs?

~~~
thristian
Are you talking about Debug mode or Release mode?

I don't know much about assembly, but in release mode it looks like you wind
up with just some setup code (starting from the label
"_ZN4main20h79637ebf645455fbeaaE") which is probably doing generic process-
startup stuff, and thenthe actual body of main (starting from the label
"main"). All the directives starting with a "." are meta-data directives,
they're not actually instructions the CPU executes.

------
tennix
I have wrote a playpen-mode for emacs last week with which we can play rust
without installing rust and without opening rust playpen in your browser.
[https://github.com/tennix/playpen-mode](https://github.com/tennix/playpen-
mode)

------
programmer_dude
No Intel syntax dis-assembly?

~~~
rer0tsaz
[https://rust.godbolt.org/](https://rust.godbolt.org/) has that and more
disassembly options

------
fny
Is backend code for this and the design for the server architecture backing it
open source? It's quite a feat to host a computing experience like this for so
many people for free.

------
tkubacki
intellisense like in
[https://dartpad.dartlang.org/](https://dartpad.dartlang.org/) would be nice

------
scanr
This looks like it's done server side. How is it sandboxed, I wonder? Would it
be feasible to do it with emscripten instead?

~~~
cmrx64
[https://github.com/thestinger/playpen](https://github.com/thestinger/playpen)
(whitelist: [https://github.com/rust-lang/rust-
playpen/blob/master/whitel...](https://github.com/rust-lang/rust-
playpen/blob/master/whitelist))

It'd probably be feasible, but a royal pain to setup.

------
kid0m4n
I wonder if it is wise to have the first example as something which panics.
Also that extra new line at the end bothers me!

~~~
ewillbefull
I don't know what you mean. The example they show is hello world.

The website will remember the last thing you compiled and ran on it, and
display that again when you come back. Perhaps you're looking at a different
code snippet.

~~~
kid0m4n
That a very weird semantic to have. I expect URLs (particularly GET requests)
to never exhibit this behavior.

~~~
woah
I've noticed a lot of sites exhibiting these faulty semantics recently. For
instance, twitter.com seems to have different content almost any time I
refresh. Me and a colleague did a quick test, submitting a GET to Twitter at
the same exact time. Her screen showed a _completely different_ set of
content. Strange and troubling.

------
hamidr
This is awesome :)

------
neverminder
Circumvented duplicated submission by removing https? Interesting.
[https://news.ycombinator.com/item?id=9543909](https://news.ycombinator.com/item?id=9543909)

~~~
flippant
I am not aware of HN etiquette. Is pointing out a duplicate submission frowned
upon?

~~~
tinco
As a guideline you can expect anything that's off-topic (like a meta remark
about it being a repost) to get at least a few downvotes. This is because when
you post a new comment it'll (often) show up as the top comment, and someone
will deem it not top-comment worthy and downvote it.

i.e.: sometimes a title is really wrong and a comment about it will get a
bunch of upvotes, and then when the title is corrected the comment will
actually get voted to the bottom because its no longer relevant or useful to
the discussion.

