Hacker News new | past | comments | ask | show | jobs | submit login
Rust Playground (rust-lang.org)
257 points by dolftax on May 24, 2015 | hide | past | favorite | 42 comments



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?


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/thestinger/playpen if you feel like it. :P


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)


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/


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/


This is the purpose of http://rustbyexample.com, not the playpen, specifically.


I'm certain this is on their to-do list.


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.


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?


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


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.


It would be great if this could also show diffs to previous versions!


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.


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.


It has multicursor support. Press Ctrl + Click :)


Seems to be powered by Ace: http://ace.c9.io


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


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


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?


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.


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


No Intel syntax dis-assembly?


https://rust.godbolt.org/ has that and more disassembly options


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.


intellisense like in https://dartpad.dartlang.org/ would be nice


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


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

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


It would require running rustc through emscripten, which is not feasible; as ELF binaries and .so objects and .rlib files, it’s currently in the vicinity of 150MB, of which 100MB is binaries which I expect would be somewhat larger in JavaScript.


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!


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.


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


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.


Fortunately there are no HTTP requests going on that cause this behavior. It is done by JS, using Local Storage.


your expectation is fundamentally flawed for many reasons, but I'll stick with the most general: the Internet has no HTTP police.


This is awesome :)


Circumvented duplicated submission by removing https? Interesting. https://news.ycombinator.com/item?id=9543909


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


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.


Pointing out recent previous discussions (with more than a couple of comments) is usually appreciated.

A complaint that someone reposted "your" link usually is not.


See the question "Are reposts ok?" in the FAQ linked at the bottom of the page.


Wow they totally robbed you of that sweet, sweet karma.


Wow they totally robbed you of that sweet, sweet karma.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: