rustc类似gcc/clang, 具体man rustc 或 rustc -hprintln!(“世界,你好”);, 或 std::iostd::io::stdin().read_line() 等std::fsmod vec;// Load the `vec` module from `vec.rs`
mod thread {
// Load the `local_data` module from `thread/local_data.rs`
// or `thread/local_data/mod.rs`.
mod local_data;
}
pub.visibility and privacy.rlib格式, 用 extern crate 导入. rustc编译时库路径指定与gcc类似use 可以绑定模块接口名到一个新的名字,方便使用,比如use std::sync::Mutex,之后就可以直接用Mutex这个短名字.use,mod都受作用域影响.let a = b; let mut somevalue = String::new(); 默认为常量(they’re immutable by default), 变量需标明mutmatch statement, if a==b { } else { }. if也是表达式, 可被变量绑定let a= if b==c {b} else {c};loop{}, for x in y{}, for( ; ;){}, while, continue, break.vec! macro.to_string(). let hachiko = "忠犬ハチ公"; for b in hachiko.as_bytes() { print!("{}, ", b); } println!(""); for c in hachiko.chars() { print!("{}, ", c); } println!(""); // This prints: // 229, 191, 160, 231, 138, 172, 227, 131, 143, 227, 131, 129, 229, 133, 172, // 忠, 犬, ハ, チ, 公,
Drop接口, 类似c++析构函数let mut myfun:fn(i32,i32)→i32;trait 编程, 扩展了OO与泛型: 参数可声明为fn myfun<T:SomeMethod> (a:T){} 其中T:SomeMethod表示拥有接口SomeMethod的任意T.ok()等方法来方便进行错误处理. 'a , 'static ;// 两斜线为普通注释; /// 三斜线支持markdown格式, /// 三个斜线的注释可被 cargo doc 生成文档