标题: Rust for Python Developers: Environment Setup [打印本页] 作者: Dinesh Vishwakarma 时间: 2019-04-01 13:10 标题: Rust for Python Developers: Environment Setup Edited by Dinesh Vishwakarma at 2019-04-01 10:42
[p name="3661" id="3661"]
(, 下载次数: 0)
上传
点击文件名下载附件
下载积分: XGold -5
[br][p name="3661" id="3661"][br][p name="3661" id="3661"]In my last article, I tried to make my[em][a href="https://medium.com/@rajasekar3eg/making-a-case-rust-for-python-developers-1a114e2d89f4" target="_blank"] [/a]case for learning rust for python developers[/em] or developers from other higher level programming languages. I have decided to contribute towards the goal of making Rust approachable for Python developers. I am writing a small series of Rust tutorials as time permits aiming at challenges I have faced while learning Rust and solutions I have found along the way.[p name="53b3" id="53b3"]This is my first article in the series of articles about making Rust approachable for Python developers and developers from other high-level languages. Here, I am going to describe my typical environment setup for programming in Rust.[p name="d5b3" id="d5b3"]I work exclusively on Linux environment. So I can’t suggest much for Windows and MacOS users. However, I guess most of these should be very similar in all these platforms.[h3 name="154a" id="154a"][br][/h3][h3 name="b386" id="b386"]IDEs:[/h3][h4 name="f66a" id="f66a"]Vim + Tmux = love[/h4][p name="0471" id="0471"]I am most at home in Vim. Tmux and Vim satisfy most of my needs while working on a new project. Technically I use NeoVim. This is how my typical environment looks like:[figure name="58e9" id="58e9"][div][div][/div][div][br][/div][div]
(, 下载次数: 0)
[br][/div][div][br][/div][div][canvas width="75" height="41"][/canvas]Tmux + Vim -> My Typical Rust Environment[/div][/div][/figure][p name="4bfe" id="4bfe"]Rust has a language server called RLS. It integrates well enough with vim plugin “ale”. It provides some functionalities like jump to definition, formatting the code, code completion, basic refactoring,etc., It also checks your code for error as you write the code.[p name="db8f" id="db8f"]Install the following cargo tools.[pre name="00f3" id="00f3"]rustup component add rustfmt[/pre][pre name="7042" id="7042"][div class="blockcode"][div id="code_jY1"][ol][li]rustup component add rls rust-analysis rust-src[/li][/ol][/div][em onclick="copycode($('code_jY1'));"]复制代码[/em][/div][/pre][pre name="6106" id="6106"]cargo +nightly install racer[/pre][p name="fcd3" id="fcd3"]If you are using Vundle plug-in manager, adding the following to your [em]vimrc[/em]or [em]nvim/init.vim[/em] will setup the Rust environment for Vim/NeoVim.[pre name="0149" id="0149"]Plugin 'racer-rust/vim-racer'[br]Plugin 'rust-lang/rust.vim'[br]Plugin 'w0rp/ale'[/pre][pre name="0a26" id="0a26"]" change the bin path as your system settings[/pre][pre name="a88a" id="a88a"]let g:racer_cmd = "/home/raja/.cargo/bin/racer" [br]let g:racer_experimental_completer = 1[/pre][pre name="11fd" id="11fd"]let g:ale_python_auto_pipenv=1[br]let b:ale_linters = {[br] \ ‘python’: <‘pylint’>,[br] \ ‘rust’: <‘rustup’, ‘run’, ‘nightly’, ‘rls’>,[br] \ ‘go’: <‘go-langserver’> }[/pre][h4 name="c714" id="c714"][strong]Clippy:[/strong][/h4][p name="b45c" id="b45c"]Clippy is Rust linter. While you are in learning phase, Clippy is extremely helpful. It identifies common mistakes and provides suggestions for modifying your code.[p name="ca5a" id="ca5a"]Install clippy using the following command:[pre name="561e" id="561e"][div class="blockcode"][div id="code_zv9"][ol][li]rustup component add clippy[/li][/ol][/div][em onclick="copycode($('code_zv9'));"]复制代码[/em][/div][/pre][p name="90c7" id="90c7"]You can run Clippy inside your project folder as follows:[pre name="45dc" id="45dc"][div class="blockcode"][div id="code_p5F"][ol][li]cargo clippy[/li][/ol][/div][em onclick="copycode($('code_p5F'));"]复制代码[/em][/div][/pre][p name="b6e2" id="b6e2"]You can find all the Clippy lints here.[p name="020c" id="020c"]While this is enough for me most of the times, most developers prefer to use IDEs. There are good reasons for that. When projects become big enough, IDEs become more convenient when working with many developers. Vim + RLS can at sometimes become unreliable and buggy as the project size grows. Refactoring is also another major hindrance as far as I have observed in Vim.[h4 name="9586" id="9586"]VS-Code:[/h4][p name="a3f9" id="a3f9"]While technically not an IDE, it generally provides a good experience for me. It also utilizes rust-rls to provide typical IDE experience. So it can also be buggy sometimes.[p name="5b8f" id="5b8f"]All you have to do is to install official Rust[a href="https://marketplace.visualstudio.com/items?itemName=rust-lang.rust" rel="nofollow noopener" target="_blank"] ([/a]rls) plugin. You are good to go. VSCode also provides debugging functionality using CodeLLDB.[p name="3230" id="3230"]To debug Rust programs, install the following extensions.[pre name="cd20" id="cd20"]CodeLLDB[/pre][pre name="bcb9" id="bcb9"]C/C++[a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools" rel="nofollow noopener" target="_blank"] [/a]extension[/pre][p name="9316" id="9316"]Change the [em]program field[/em] in [em]launch.json[/em] to your debug binary as follows.[pre name="b8fd" id="b8fd"][br]"configurations": <[br] {[br] "name": "(gdb) Launch",[br] "type": "lldb",[br] "request": "launch",[br] "program": "[strong]path_to_your_project/target/debug/project_name[/strong]",[br] "args": <>,[br] "sourceLanguages": <"rust">,[br] "cwd": "${workspaceFolder}",[br] "environment": <>,[br] "externalConsole": true,[br] "description": "Enable pretty-printing for gdb",[br] "text": "-enable-pretty-printing",[br] "ignoreFailures": true[br] }[br] >[br] }[br] >[/pre][figure name="7267" id="7267"][div][/div][div][br][/div][div][br][/div][div][canvas width="75" height="41"][/canvas]
(, 下载次数: 0)
上传
点击文件名下载附件
下载积分: XGold -5
Rust in VSCode[br][/div][/figure][h4 name="9cc1" id="9cc1"]IntelliJ Rust:[/h4][p name="6798" id="6798"]This is by far the most reliable IDE for Rust based on my experience. Code completion, jump to definition, refactoring, on the fly error analysis,etc., all work very well and it’s butter smooth. However, debugging is available only on CLion(paid version). You have to install Rust-plugin and it just works.[figure name="6ca0" id="6ca0"][div][div][/div][div][br][/div][div]
(, 下载次数: 0)
上传
点击文件名下载附件
下载积分: XGold -5
[br][/div][div][canvas width="75" height="41"][/canvas]IntelliJ Rust[/div][/div][/figure][p name="a560" id="a560"]So overall, for a relatively small personal project, I tend to use Vim mostly. For large projects, I tend to use IntelliJ Rust while developing and use VSCode while debugging.[h3 name="d9aa" id="d9aa"][br][/h3]
作者: jk885884 时间: 2019-04-01 14:11
Good brother 作者: Dinesh Vishwakarma 时间: 2019-04-01 14:34
Thanks brother!
欢迎光临 XCLUB-COOL STUFF AROUND YOU (https://admin.in.ilovexclub.com/)