]> git.proxmox.com Git - rustc.git/blob - src/doc/rust-by-example/src/meta/playpen.md
New upstream version 1.64.0+dfsg1
[rustc.git] / src / doc / rust-by-example / src / meta / playpen.md
1 # Playpen
2
3 The [Rust Playpen](https://github.com/rust-lang/rust-playpen) is a way to experiment with Rust code through a web interface. This project is now commonly referred to as [Rust Playground](https://play.rust-lang.org/).
4
5 ## Using it with `mdbook`
6
7 In [`mdbook`][mdbook], you can make code examples playable and editable.
8
9 ```rust,editable
10 fn main() {
11 println!("Hello World!");
12 }
13 ```
14
15 This allows the reader to both run your code sample, but also modify and tweak it. The key here is the adding the word `editable` to your codefence block separated by a comma.
16
17 ````markdown
18 ```rust,editable
19 //...place your code here
20 ```
21 ````
22
23 Additionally, you can add `ignore` if you want `mdbook` to skip your code when it builds and tests.
24
25 ````markdown
26 ```rust,editable,ignore
27 //...place your code here
28 ```
29 ````
30
31 ## Using it with docs
32
33 You may have noticed in some of the [official Rust docs][official-rust-docs] a button that says "Run", which opens the code sample up in a new tab in Rust Playground. This feature is enabled if you use the #[doc] attribute called [`html_playground_url`][html-playground-url].
34
35 ### See also:
36
37 - [The Rust Playground][rust-playground]
38 - [The next-gen playpen][next-gen-playpen]
39 - [The rustdoc Book][rustdoc-book]
40
41 [rust-playground]: https://play.rust-lang.org/
42 [next-gen-playpen]: https://github.com/integer32llc/rust-playground/
43 [mdbook]: https://github.com/rust-lang/mdBook
44 [official-rust-docs]: https://doc.rust-lang.org/core/
45 [rustdoc-book]: https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html
46 [html-playground-url]: https://doc.rust-lang.org/rustdoc/the-doc-attribute.html#html_playground_url