Rust

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版本。
时间: 2024-08-18 20:02:19

Rust的相关文章

MIPS平台OpenWrt路由器系统内的Rust应用程序开发

作者:Liigo(庄晓立) 日期:2014年9月17日 原创链接:http://blog.csdn.net/liigo/article/details/39347541 版权所有,转载请注明出处:http://blog.csdn.net/liigo 目标 使用 Rust 语言,交叉编译开发 MIPS(el) + OpenWrt 路由器平台下的应用软件. 编译rustc 首先自行编译Rust编译器源代码,生成支持 mipsel-linux 平台的交叉编译器rustc ./configure --t

Rust 1.7.0 匹配器 match 的简介和使用

使用过正則表達式的人应该都知道 matcher ,通过 matcher 匹配器运算正則表達式,完毕一系列的匹配规则. 在Rust 中 没有 switch 语句.matcher 就是 switch 的一个变形,但比其它语言中的 switch 更强大! 一.简单举例说明 简单的 matcher 和 if 语句很相似,假设是简单的条件推断能够用if语句: let n = 5; if n < 0 { print!("{} is negative", n); } else if n >

Eclipse环境安装rust

参考 https://rustdt.github.io/ https://github.com/RustDT/RustDT/blob/latest/documentation/UserGuide.md#user-guide https://stackoverflow.com/questions/33570021/how-to-set-up-gdb-for-debugging-rust-programs-in-windows/33570022#33570022 1.安装RUST 语言工具 在htt

Rust 学习记录(Nightly)

2.1 安装 $ curl -L https://static.rust-lang.org/rustup.sh | sudo sh 2.2 Hello, world! 创建项目 $ mkdir ~/projects $ cd ~/projects $ mkdir hello_world $ cd hello_world 创建 main.rs,当前目录结构 projects/ └── hello_world └── main.rs 编写代码 fn main() { println!("Hello,

Installing Rust

1.官方说明 If you're on Linux or a Mac, all you need to do is this (note that you don't need to type in the $s, they just indicate the start of each command): curl -s https://static.rust-lang.org/rustup.sh | sudo sh 2.我的环境: Centos 7.0 64位 ①执行命令:curl -s h

Rust 1.7.0 macro宏的复用 #[macro_use]的使用方法

Rust 1.7.0 中的宏使用范围包含三种情况: 第一种情况是宏定义在当前文件里.这个文件可能是 crate 默认的 module,也可能是随意的 module 模块. 另外一种情况是宏定义在当前 crate .可是不是在当前文件里,而是其它 module 模块中. 第三种情况是宏定义在其它的 crate 中.或者其它的 crate 子模块中. 使用#[macro_use] 能够使被注解的module模块中的宏应用到当前作用域中.或者凝视crate中的宏应用到当前crate作用域中. 第一种情

rust 参考的资料 转

http://blog.csdn.net/loveisasea/article/details/46292715 rust官方学习文档: 1.http://doc.rust-lang.org/book/README.html (英文:rust参考手册) 2.https://www.gitbook.com/book/kaisery/rust-book-chinese(中文:rust参考手册,翻译略显晦涩) 3.http://rustbyexample.com/index.html 4.http:/

Atitit.rust语言特性&#160;attilax&#160;总结

Atitit.rust语言特性 attilax 总结 1. 创建这个新语言的目的是为了解决一个顽疾:软件的演进速度大大低于硬件的演进,软件在语言级别上无法真正利用多核计算带来的性能提升.1 2. 不会出现Null指针等等1 2.1.1. Rust 1.1 稳定版 更新内容1 2.1.2. Rust 1.2 测试版 更新内容2 3. RAII2 3.1. 无数据竞争(Data Race)…无需竞争的并发,Rust能够确保在并发编程中的数据安全3 4. 是基于继承的组合,Rust能基于继承实现组合,

半个月使用rust语言的体验

从第一次下载rust语言的编译器到今天刚好第14天. 简单说一下对这个语言的感觉吧. 一.性能 把以前用java写的一个中文地址切分的算法,用rust重新实现了一下(https://github.com/naturemickey/addressCut_use_rust).运行的速度上,rust的release版本要比java快上一倍左右. java版本的代码量是800多行,而rust版本的代码量是600多行. 这个体验还是很不错的,毕竟才刚刚开始学习rust语言,很多代码自己都觉得写得丑陋无比(

Rust这个新的语言

Rust初步(七):格式化 摘要: 在Rust中,如果要进行屏幕输出,或者写入到文件中,需要对数据进行格式化.这一篇总结一下它所支持的几种格式化方式. 这篇文章参考了以下官方文档,不过,按照我的风格,我还是会突出于C#语言的比较,这样可能更好懂一些. http://rustbyexample.com/hello/print.html http://doc.rust-lang.org/std/fmt/ http://rustbyexa...阅读全文 posted @ 2015-08-27 13:0