Rust

维基百科,自由的百科全书
跳转至: 导航搜索
Rust
Rust programming language black logo.svg
编程范型 編譯語言並行計算
函數程式語言指令式編程
物件導向程式設計結構化編程
发行时间 2010年
設計者 Graydon Hoare
實作者 Mozilla
最新测试版发行日期 0.11[1] / 2014年7月2日;23天前 (2014-07-02)
型態系統 靜態類型強型別類型推論結構類型英语Structural type system
啟發語言 Alef英语Alef (programming language)
C♯
C++
Camlp4英语Camlp4
Common Lisp
Erlang
Haskell
Hermes
Limbo
Napier
Napier88
Newsqueak
NIL
Ruby
Sather
Standard ML
影響語言 Swift[2]
作業系統 Linux
Mac OS X
Windows
FreeBSD
許可證 Apache许可证2.0及MIT許可證[3]
常用文件扩展名 .rs
網站 rust-lang.org

Rust是一个由Mozilla[4]主导开发的实验性跨平台编译型编程语言。它的设计准则为“安全,并发,实用”,[5][6]支持函数式并发式程序式以及面向对象的编程风格。

历史[编辑]

2006年,Rust作为Graydon Hoare的个人项目首次出现。

2009年,Graydon Hoare成为Mozilla雇员[7]

2010年,Rust首次作为Mozilla官方项目出现[8]。同年,Rust开始从初始编译(由OCaml写成)转变为自编译[9]

2011年,Rust成功的完成了移植[10]。Rust的自编译器采用LLVM作为其编译后端。

2012年1月20日,第一个有版本号的预览版Rust编译器发布[11]。当前最新版本为0.7,于2013年7月发布[1]

2013年4月4日,Mozilla基金會宣布將與三星集團合作開發瀏覽器排版引擎Servo将以Rust來實作[12]

代码示例[编辑]

下面的代码在Rust 0.11中测试通过,在将来的版本中语法和语义可能会发生变化。

Hello World[编辑]

fn main() {
    println!("hello?");
}

阶乘[编辑]

下面是两个不同版本的阶乘函数,分别以递归循环的方法写成:

/* The branches in this function exhibit Rust's optional implicit return values,
   which can be utilized where a more "functional" style is preferred.
   Unlike C++ and related languages, Rust's `if` construct is an expression
   rather than a statement, and thus has a return value of its own. */
fn fac_recur(n: int) -> int {
    if n <= 1 { 1 }
    else { n * fac_recur(n-1) }
}
 
fn fac_iter(n: int) -> int {
    // Variables must be declared with the `mut` keyword in order to be mutable.
    let mut i = 1,
            result = 1;
    while i <= n {
        result *= i;
        i += 1;
    }
    return result;  // An explicit return, in contrast to the above.
}

并发[编辑]

一个简单的Rust并发示例:

use task::spawn;
 
/* This function creates ten "tasks" that all execute concurrently.
   Run it to observe the irregular linebreaks that result as each task races
   on stdout, due to the fact that `io::println` may yield to the task
   scheduler between printing its argument and printing a newline. */
fn main() {
    // `times` is a method on numeric types whose only argument is a closure.
    for 10.times {
        do spawn {
            // `each` is a method that accepts a closure with one argument.
            for [1, 2, 3].each |item| {
                // `fmt!` is a macro that statically checks its format string.
                io::println(fmt!("%d", *item));
            }
        }
    }
}

开发过程[编辑]

在早期的开发版本中,Rust禁止使用非ASCII码字符作为变量名,主要理由在于大多数非英语使用者仍会使用ASCII字符作为变量名,然而,这个限制遭到了许多批评[13]。在2011年2月的一次更新中,Rust去除了这个限制[14]

语言演变[编辑]

版本演变参见这里

发行历史
版本号 日期
0.11 2014-07-02
0.10 2014-04-03
0.9 2014-01-09
0.8 2013-09-26
0.7 2013-07-03
0.6 2013-04-02
0.5 2012-12-20
0.4 2012-10-12
0.3 2012-07-12
0.2 2012-03-28
0.1 2012-01-20

参见[编辑]

參考資料[编辑]

  1. ^ 1.0 1.1 Rust Release Notes
  2. ^ Lattner, Chris. Chris Lattner's Homepage. Chris Lattner. 2014-06-03 [2014-06-03]. "The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list." 
  3. ^ COPYRIGHT. Rust compiler source repository. [2012-12-17]. 
  4. ^ The Rust Language. Lambda the Ultimate. 2010-07-08 [2010-10-30]. 
  5. ^ The Rust Programming Language. [2012-10-21]. 
  6. ^ Doc language FAQ. [2012-10-21]. 
  7. ^ Project FAQ. 2010-09-14 [2012-01-11]. 
  8. ^ Future Tense. 2011-04-29 [2012-02-06]. "At Mozilla Summit 2010, we launched Rust, a new programming language motivated by safety and concurrency for parallel hardware, the “manycore” future which is upon us." 
  9. ^ Hoare, Graydon. Rust Progress. 2010-10-02 [2010-10-30]. 
  10. ^ Hoare, Graydon. [rust-dev] stage1/rustc builds. 2011-04-20 [2011-04-20]. "After that last change fixing the logging scope context bug, looks like stage1/rustc builds. Just shy of midnight :)" 
  11. ^ catamorphism. Mozilla and the Rust community release Rust 0.1 (a strongly-typed systems programming language with a focus on memory safety and concurrency). 2012-01-20 [2012-02-06]. 
  12. ^ http://arstechnica.com/information-technology/2013/04/samsung-teams-up-with-mozilla-to-build-browser-engine-for-multicore-machines/
  13. ^ Jelliffe, Rick. Vale Java? Scala Vala palava. 2010-11-08 [2012-03-29]. "… It is just plain ignorant to say that non-English programmers always write with ASCII. (Just as it would be ignorant to say that they never do.) It is that kind of rather blithe dismissal that foreign cultures and languages need to be supported that creates extra unnecessary barriers. That argument ran out of legs in the early 1990s: all platforms have well -established Unicode libraries with serviceable properties for this…" 
  14. ^ Commit dabccadd3202513ab0bcb424e2c62c90ab23062d. 2011-02-26 [2012-01-11]. 

外部链接[编辑]