diff --git a/theme/book.js b/theme/book.js index 3c46f6af926a..6aba2b1d5c95 100644 --- a/theme/book.js +++ b/theme/book.js @@ -110,10 +110,17 @@ function playground_text(playground, hidden = true) { } function run_rust_code(code_block) { - var result_block = code_block.querySelector(".result"); + var result_stderr_block = code_block.querySelector(".result.stderr"); + if (!result_stderr_block) { + result_stderr_block = document.createElement('code'); + result_stderr_block.className = 'result stderr hljs nohighlight'; + + code_block.append(result_stderr_block); + } + var result_block = code_block.querySelector(".result.stdout"); if (!result_block) { result_block = document.createElement('code'); - result_block.className = 'result hljs language-bash'; + result_block.className = 'result stdout hljs nohighlight'; code_block.append(result_block); } @@ -127,10 +134,13 @@ function playground_text(playground, hidden = true) { edition = "2021"; } var params = { - version: "stable", - optimize: "0", + backtrace: true, + channel: "stable", code: text, - edition: edition + edition: edition, + mode: "debug", + tests: false, + crateType: "bin", }; if (text.indexOf("#![feature") !== -1) { @@ -141,7 +151,7 @@ function playground_text(playground, hidden = true) { const playgroundModified = isPlaygroundModified(code_block); const startTime = window.performance.now(); - fetch_with_timeout("https://play.rust-lang.org/evaluate.json", { + fetch_with_timeout("https://play.rust-lang.org/execute", { headers: { 'Content-Type': "application/json", }, @@ -158,13 +168,15 @@ function playground_text(playground, hidden = true) { "latency": (endTime - startTime) / 1000, }); - if (response.result.trim() === '') { + if (response.stdout.trim() === '') { result_block.innerText = "No output"; result_block.classList.add("result-no-output"); } else { - result_block.innerText = response.result; + result_block.innerText = response.stdout; result_block.classList.remove("result-no-output"); } + + result_stderr_block.innerText = response.stderr; }) .catch(error => { const endTime = window.performance.now();