rust 学习入门

来源:互联网 发布:淘宝网电动车挡风被 编辑:程序博客网 时间:2024/06/07 05:01

Rust is a systems programming language that runs blazingly fast, prevents nearly all segfaults, and guarantees thread safety. 
Show me!

Recommended Version:
1.1.0 (Windows installer)
InstallOther Downloads

Featuring

  • zero-cost abstractions
  • move semantics
  • guaranteed memory safety
  • threads without data races
  • trait-based generics
  • pattern matching
  • type inference
  • minimal runtime
  • efficient C bindings
// 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);
}
0 0
原创粉丝点击