Rust-lang(hello world)
来源:互联网 发布:运营数据分析的步骤 编辑:程序博客网 时间:2024/05/24 13:28
最近,突然迷上了Rust!Rust在中国还是小众中的小众!有个一年不会更新一次的论坛,没有任何中文,资料,只能去死磕官方文档!这个就是我死磕官方文档的笔记,是笔记,笔记,不是翻译!
install
略过吧,官网一看就会安装!
hello world
fn main(){ println!("{}","hello world");}
使用命令rustc main.rs 编译, ./main 运行。
cargo
Rust 自带的项目构建工具。
$ mkdir src$ mv main.rs src/main.rs$ rm main
在工程目录下创建文件Cargo.toml,然后配置它。
[package]name = "rust-study"version = "0.1.0"authors = ["madong"][dependencies]rand="0.3.0"
main.rs code:
extern crate rand;use std::io;use std::cmp::Ordering;use rand::Rng;fn main() { println!("Hello, world!"); let secret_number = rand::thread_rng().gen_range(1,101); println!("Please gusses secret number !"); let mut number = String::new(); io::stdin().read_line(&mut number).expect("Failed to read_line"); let number : u32 = number.trim().parse().expect("Please type a number"); println!("Hello,your number is {}", number); println!("The secret number is: {}", secret_number); match number.cmp(&secret_number) { Ordering::Less => println!("too small!"), Ordering::Greater => println!("too big!"), Ordering::Equal => println!("You win!"), }}
在工程目录下运行,cargo run 即可运行程序!
结束 hello world!
0 0
- Rust-lang(hello world)
- Rust-lang(hello world 续)
- 边做边学Rust之Hello World
- Rust hello world 语法讲解
- 第一个Rust程序——Hello,world!
- 通过例子学习Rust之 1 Hello World
- socket (hello world)
- Qsort(Hello World!)
- (1)Hello World
- hello world(指针)
- Hello World!【Hello World】
- 【Python】(二)hello world,hello you
- OSGI(四)Hello World
- Win32编程(Hello World)
- javaSE(hello,world)(二)
- 第一章,Hello World(Lua)
- 11636 - Hello World!(水题)
- SpringMVC---Hello World(1)
- c语言中关键字 static 的相关理解
- 奇葩bug
- Android: 用jni 获取MAC地址
- Maven创建EJB
- JVM内存划分与GC机制
- Rust-lang(hello world)
- leetcode 1---Two Sum 数组 哈希
- unity3D 涂涂乐使用shader实现上色效果
- swift uiwebview 数字被点击默认成拨打电话
- web 页面打开QQ聊天框
- ArcEngine要素转点,要素节点转点
- iOS开发~子视图超过父视图范围的事件响应问题
- centos6.5环境基于conga的web图形化界面方式配置rhcs集群
- Linux下编写程序