rust-lang / rust-playground

The Rust Playground
https://play.rust-lang.org/
Apache License 2.0
1.27k stars 207 forks source link

Easily embed interactive code snippets #199

Open dvberkel opened 7 years ago

dvberkel commented 7 years ago

The Rust book and other guides use the playground to execute code snippets and display the results inline. This is an awesome way to increase interactivity, especially when the examples are editable as seen in the Rust by Example book.

With some work it is possible to mimic this effect by yourself, but it would be great if there is an easy way to repeatedly include interactive Rust snippets in a website, blog post or HTML presentation.

I was thinking of an embed button that offers a copyable snippet of code, just like the Travis CI aid for embedding the build badge. A corresponding wiki page could provide instructions how to set things up.

Is this something that people are interested in?

shepmaster commented 7 years ago

An interesting idea!

My first uncollected thoughts:

  1. I would prefer to avoid using the the API route that the book / docs use. It has to be there forever for compatibility, but I'd rather use something a little more principled.
  2. Rustdoc has magic code that allows hiding parts of the example code. Reimplementing something equivalent seems less-than-ideal.
  3. It feels like any embedded content will also come with desires to theme the content to match the hosting site.
  4. Embedding an editor has even more complication and the possibility of code bloat.

I'm not against the idea, I just naturally tend to the pessimistic side of things ;-)

What might be "better" is splitting such an idea into the two parts. The Playground could learn an official API and another project could provide the embedding assistance.

dvberkel commented 7 years ago

@shepmaster Thanks for your feedback. I totally appreciate your skepticism. I fully understand that accepting a feature into a project, means that the burden of maintaining it falls on you. I don't think this is pessimism, just realism.

How would the playground API look like, and how would it differ from the API route the book uses?

alanwsmith commented 1 year ago

I've been looking around and haven't found a way to embed inside other websites. I'm guessing that's still not possible given the lack of activity on this issue :-)

I publish my notes on my blog when I'm learning new things and it would be super cool to have live snippets. So, I want to make sure I'm not missing something.

And a follow up question, if I can pull out the parts from the source code and get it working on my blog, is it okay to use the playground services to do the processing?