码迷,mamicode.com
首页 > 其他好文 > 详细

Rust

时间:2016-07-19 18:38:25      阅读:668      评论:0      收藏:0      [点我收藏+]

标签:

Rust
https://www.rust-lang.org/en-US/
https://github.com/rust-lang/rust


安装
方式一:Homebrew(mac)
$ brew install rust


方式二:rust-lang.org(linux, mac)
1. 从官网下载安装包
   https://www.rust-lang.org/en-US/downloads.html
2. 安装 rust
Mac是pkg文件、Windows是msi文件。
以linux的tar.gz包为例:
$ tar xzf rust-1.10.0-x86_64-unknown-linux-gnu.tar.gz
$ cd rust-1.10.0-x86_64-unknown-linux-gnu
$ sudo install.sh
(详细见REMDME.md文件)
$ cd ..
$ rm -rf rust-1.10.0-x86_64-unknown-linux-gnu


方式三:源码
需要手动编译 rust 和 cargo 源码。
详细见它们的 github 页面。


安装工具
代码提示器 racer 和编码格式化 rustfmt 工具
$ cargo install racer      # https://github.com/phildawes/racer
$ cargo install rustfmt    # https://github.com/rust-lang-nursery/rustfmt
如果网络问题,可以换时间多尝试几次,也可以到其github页面查看下载源码安装的方法

下载rust源码,racer需要rust源码
$ git clone --depth 1 https://github.com/rust-lang/rust.git

配置环境变量
RUST_SRC_PATH 配置rust源码/src路径。
如:
$ echo ‘export RUST_SRC_PATH="$HOME/Developer/github/rust/src"‘ >> ~/.zshrc~/.bash_profile
$ echo ‘export RUST_SRC_PATH="$HOME/Developer/github/rust/src"‘ >> ~/.bashrc        # Ubuntu Desktop
$ echo ‘export RUST_SRC_PATH="$HOME/Developer/github/rust/src"‘ >> ~/.zshrc         # Zsh
创建软链接
$ ln -s ~/.cargo/bin/racer /usr/local/bin/racer
$ ln -s ~/.cargo/bin/rustfmt /usr/local/bin/rustfmt
$ ln -s ~/.cargo/bin/cargo-fmt /usr/local/bin/cargo-fmt
测试racer
$ racer complete std::io::B
MATCH BufReader,48,11,/Users/yk/Desktop/Developer/github/rust/src/libstd/io/buffered.rs,Struct,pub struct BufReader<R>
MATCH BufWriter,300,11,/Users/yk/Desktop/Developer/github/rust/src/libstd/io/buffered.rs,Struct,pub struct BufWriter<W: Write>
MATCH BufRead,1199,10,/Users/yk/Desktop/Developer/github/rust/src/libstd/io/mod.rs,Trait,pub trait BufRead: Read
MATCH Bytes,1532,11,/Users/yk/Desktop/Developer/github/rust/src/libstd/io/mod.rs,Struct,pub struct Bytes<R>

创建一个helloworld
$ cargo new helloworld --bin
$ cd helloworld
$ cargo build     # 编译debug版本。release版本请加 --release 参数
$ ./target/debug/helloworld
Hello, world!




TextMate
打开一个rs文件,会提示安装Rust Bundle
打开一个toml文件,会提示安装Toml Bundle
CMD+B编译,CMD+R运行。


Sublime Text
可利用package controller安装一些扩展:
Rust                # 语法高亮加强(新版Sublime Text 3自带Rust高亮,可忽略)
RustAutoComplete    # 利用Racer自动完成,需要根据说明配置racer和rust/src路径
BeautifyRust        # 利用rustfmt格式化代码,需要根据说明配置rustfmt路径
CMD+B编译或运行,CMD+SHIFT+B更换编译或运行。


VSCode
用VSCode打开helloworld目录
安装Rusty Code扩展:CMD+SHIFT+P(或者F1),输入:ext install,搜索rusty code,安装之。
配置扩展:
在helloworld项目目录新建一个.vscode目录,然后在.vscode目录下建立settings.json
内容如下:
{
    "rust.racerPath": "/usr/local/bin/racer"
    "rust.rustLangSrcPath": "/Users/yk/Desktop/Developer/github/rust/src" of Rust sources
    "rust.rustfmtPath": "/usr/local/bin/rustfmt"
    "rust.cargoPath": null, // Specifies path to Cargo binary if it‘s not in PATH
    "rust.cargoHomePath": null, // Path to Cargo home directory, mostly needed for racer. Needed only if using custom rust installation.
    "rust.formatOnSave": false, // Turn on/off autoformatting file on save (EXPERIMENTAL)
    "rust.checkOnSave": false, // Turn on/off `cargo check` project on save (EXPERIMENTAL)
    "rust.checkWith": "build" // Specifies the linter to use. (EXPERIMENTAL)
}
到.gitignore文件,添加一行:.vscode
回到main.rs文件,按CMD+SHIFT+P(或者F1),输入format,选择Format Code(记住快捷键SHIFT+OPTION+F)即可格式化代码。
输入std::即可看见rancer代码提示。
按按CMD+SHIFT+P(或者F1),输入cargo,可看见一组cargo命令,其中CTRL+SHIFT+B编译debug版,CTRL+SHIFT+R运行debug版,
快捷键加option是release版本。

 

Rust

标签:

原文地址:http://www.cnblogs.com/Bob-wei/p/5685731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!