Rust的包管理器Cargo
来源:互联网 发布:mac os lion无法升级 编辑:程序博客网 时间:2024/05/13 03:38
安装
.
├── Cargo.toml
└── src
└── main.rs
安装Cargo最简单的方法是使用rustup脚本获得:
$ curl -sS https://static.rust-lang.org/rustup.sh | sudo bash
你将会获得最新版本的Rust和最新版本的Cargo。你需要每天运行一次该脚本来获取最新升级。
如果你使用的是Windows,直接下载最新版的32位(Rust和Cargo)或64位(Rust和Cargo)安装包。
或者,你可以从源码构建Cargo。
让我们开始吧
用Cargo开始一个新项目,使用 cargo new:
$ cargo new hello_world --bin
我们传递--bin是因为我们制作二进制程序:如果我们只做一个库,我们将不会传递--bin。
查看一下Cargo为我们生成了什么:
$ cd hello_world
$ tree ..
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
这就是我们开始所需要的所有东西。首先,查看一下Cargo.toml文件内容:
[package] name = "hello_world" version = "0.1.0" authors = ["Your Name <you@example.com>"]
这被称为“manifest”,它包含Cargo编译工程所需要的所有元数据。
src/main.rs的内容如下:
fn main() { println!("Hello, world!"); }
Cargo为我们生成了一个‘hello world’,让我们编译它:
$ cargo build
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
运行它:
$ ./target/debug/hello_world
Hello, world!
Hello, world!
我们也可以使用cargo run来编译并运行,一步完成:
$ cargo run
Fresh hello_world v0.1.0 (file:///path/to/project/hello_world)
Running `target/hello_world`
Hello, world!
Fresh hello_world v0.1.0 (file:///path/to/project/hello_world)
Running `target/hello_world`
Hello, world!
深入学习
更多Cargo的细节,请查看Cargo手册。
转载请注明出处:http://blog.csdn.net/ucan23/article/details/45667187
1 0
- Rust的包管理器Cargo
- Rust使用Cargo
- rust的应用程序和cargo 的基本使用
- 【Rust】在使用Cargo镜像的情况下,使用Racer补全第三方库
- Rust 中项目构建管理工具 Cargo简介
- 如何利用科大源提速Cargo和Rust
- Rust: Atom中cargo build error
- mac的包管理器
- mac的包管理器
- Rust 功能函数的关系、包和模块简介
- python 的包管理器 easy_install
- Composer PHP的包管理器
- YUM 包管理器的使用
- Ubuntu下的包管理器
- Lua的包管理器LuaRockts
- Cargo
- Cargo本地/远程部署war包的Ant脚本编写方式
- Rust基础笔记:闭包
- swift dictonary convert to (转为 )json
- 常见音频编码格式(注:编码格式不同于文件格式)
- 关于AppDelegate及内部方法的简单介绍
- android.support.v8.renderscript相关类找不到的错误解决
- 调试引发的一场腥风血雨
- Rust的包管理器Cargo
- 如何在图片中附加rar文件
- Android parcelable 解析
- ORACLE中的(+) 与join
- 文件上传漏洞
- 2015可视化大事件一览
- C++类中调用与成员函数同名的全局函数
- scala安装
- hihocoder 1166 交换代数|HDU 4870 Rating 等(区间翻转,高斯消元求期望)