RustMozilla的編程語(yǔ)言
Rust 是 Mozilla 的一個(gè)新的編程語(yǔ)言,由web語(yǔ)言的領(lǐng)軍人物Brendan Eich(js之父),Dave Herman以及Mozilla公司的Graydon Hoare 合力開(kāi)發(fā)。
創(chuàng)建這個(gè)新語(yǔ)言的目的是為了解決一個(gè)很頑疾的問(wèn)題:軟件的演進(jìn)速度大大低于硬件的演進(jìn),軟件在語(yǔ)言級(jí)別上無(wú)法真正利用多核計(jì)算帶來(lái)的性能提升。Rust是針對(duì)多核體系提出的語(yǔ)言,并且吸收一些其他動(dòng)態(tài)語(yǔ)言的重要特性,比如不需要管理內(nèi)存,比如不會(huì)出現(xiàn)Null指針等等。
特點(diǎn):
-
零成本的抽象
-
移動(dòng)語(yǔ)義
-
保證內(nèi)存安全
-
線程沒(méi)有數(shù)據(jù)競(jìng)爭(zhēng)
-
trait-based泛型
-
模式匹配
-
類型推斷
-
最小運(yùn)行時(shí)
-
高效的C綁定
// This code is editable and runnable!
fn main() {
// A simple integer calculator:
// `+` or `-` means add or subtract by 1
// `*` or `/` means multiply or divide by 2
let program = "+ + * - /";
let mut accumulator = 0;
for token in program.chars() {
match token {
'+' => accumulator += 1,
'-' => accumulator -= 1,
'*' => accumulator *= 2,
'/' => accumulator /= 2,
_ => { /* ignore everything else */ }
}
}
println!("The program \"{}\" calculates the value {}",
program, accumulator);
}評(píng)論
圖片
表情
