<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                我們今天來配置下vscode+rust。 vscode開發rust很方便。但配置有點坑,我們都認為vscode很簡單,很完善。 但這里很多同學也出現不少問題。 我們在這里簡單記錄下win7下配置的過程,跟著我一步步來,應該就可打造你的屠龍寶刀。 首先,我們安裝插件: Rust Extension Pack Rust Test Explorer 然后打開上一篇文章的工程:`hello-rust`,見:# rustlang語言零基礎快速入門(1) 打開command palette (Ctrl-Shift-P):輸入:build,然后選擇:Tasks: Configure Default Build Task,再選擇:Rust: cargo build ![](https://img2018.cnblogs.com/blog/544318/201911/544318-20191119111544669-1539794949.png) ![](https://img2018.cnblogs.com/blog/544318/201911/544318-20191119111752805-826086223.png) ?vscode會自動生成一個json文件: ?**//?See?https://go.microsoft.com/fwlink/?LinkId=733558?** **????//?for?the?documentation?about?the?tasks.json?format** **????"version":?"2.0.0",** **????"tasks":?\[** **????????{** **????????????"label":?"cargo?run",** **????????????"type":?"shell",** **????????????"command":?"cargo",** **????????????"args":?\[** **????????????????"run"** **????????????\],** **????????????"group":?{** **????????????????"kind":?"build",** **????????????????"isDefault":?true** **????????????}** **????????}** **?這里,我們直接按“CTRL+SHIFT+P”,選擇:“Task:Run Build Task”,或者直接按快捷鍵“CTRL+F9”** ![](https://img2018.cnblogs.com/blog/544318/201911/544318-20191120103110135-538352550.png) VSCODE會自動BUILD,并在終端窗口顯示打印結果: \------------------------------------------------------- \> Executing task: cargo run < ?? Compiling hello-rust v0.1.0 (E:\\code\\rustProject\\hello-rust) ??? Finished dev \[unoptimized + debuginfo\] target(s) in 2.11s ???? Running `target\\debug\\hello-rust.exe` \---------------------------- | Hello fellow Rustaceans! | \---------------------------- ????????????? \\ ?????????????? \\ ????????????????? \_~^~^~\_ ????????????? \\) /? o o? \\ (/ ??????????????? '\_?? -?? \_' ??????????????? / '-----' \\ Terminal will be reused by tasks, press any key to close it. \-------------------------------------------------------------- ?下面配置測試task: 先在main函數下面增加測試代碼: ~~~ #[test] fn should_fail() { unimplemented!(); } 保存后,按快捷鍵:“CTRL+SHIFT+P”,輸入:Task,選擇“Tasks: Configure Default Test Task”,然后選擇:“Rust: cargo test” ~~~ ![](https://img2018.cnblogs.com/blog/544318/201911/544318-20191120103954112-1485635816.png) ?![](https://img2018.cnblogs.com/blog/544318/201911/544318-20191120104027408-1155904162.png) ~~~ vscode自動生成: ~~~ { ????????????"type":?"cargo", ????????????"subcommand":?"test", ????????????"problemMatcher":?\[ ????????????????"$rustc" ????????????\], ????????????"group":?{ ????????????????"kind":?"test", ????????????????"isDefault":?true ????????????} ????????} ~~~ 保存后,按按快捷鍵:“CTRL+SHIFT+P”,輸入:Task:Run test Task,回車。 vscode自動運行測試用例,并打印結果: --------------------------------------- > Executing task: cargo test < ?? Compiling hello-rust v0.1.0 (E:\code\rustProject\hello-rust) ??? Finished dev [unoptimized + debuginfo] target(s) in 1.77s ???? Running target\debug\deps\hello_rust-bfa762df5afd173e.exe running 1 test test should_fail ... FAILED failures: ---- should_fail stdout ---- thread 'should_fail' panicked at 'not yet implemented', src\main.rs:14:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. failures: ??? should_fail test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out error: test failed, to rerun pass '--bin hello-rust' The terminal process terminated with exit code: 1 Terminal will be reused by tasks, press any key to close it. ----------------------------------------------------------- 下面繼續配置DEBUG環境。 這里參照這個文章:https://www.forrestthewoods.com/blog/how-to-debug-rust-with-visual-studio-code/ 簡單來說,你按如下幾步來配置就可以: 1.安裝: C/C++ extension. Native Debug extension 2.在debug面板,新建一個新的配置,如下: ~~~ ![](https://img2018.cnblogs.com/blog/544318/201911/544318-20191120111411506-813620503.png) 然后選擇:“C++ (Windows)” environment 會自動生成launch.json代碼,如下 : { ????//?Use?IntelliSense?to?learn?about?possible?attributes. ????//?Hover?to?view?descriptions?of?existing?attributes. ????//?For?more?information,?visit:?https://go.microsoft.com/fwlink/?linkid=830387 ????"version":?"0.2.0", ????"configurations":?\[ ????????{ ????????????"name":?"(Windows)?Launch", ????????????"type":?"cppvsdbg", ????????????"request":?"launch", ????????????"program":?"${workspaceFolder}/target/debug/hello-rust.exe", ????????????"args":?\[\], ????????????"stopAtEntry":?false, ????????????"cwd":?"${workspaceFolder}", ????????????"environment":?\[\], ????????????"externalConsole":?false ????????} ????\] } ~~~ 其中program的值改為你自己的exe的路徑,比如我的就是: ${workspaceFolder}/target/debug/hello-rust.exe ~~~ ~~~ 這時,你直接按F5,你就進入debug狀態,你現在可以設置斷點了。 ~~~ ~~~ 如果,你順利走到這一步,恭喜你,你已經基本配置好rust的開發環境。 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看