PDF
(mutable)(immutable)1Rust(1) Contents(mutable)(immutable) ................................................................. 1 ............................................................................................... 2 .................................................................................................... 3 ............................................................................................... 3rust .................................................................................. 5使fn main() { println!("Hello world!");}rustc hell.rs -o hello.out && ./hello.out(mutable)(immutable)使使let i = 32; // immutablelet mut i = 32; |4 | let i = 10; | - | | | first assignment to `i` | help: make this binding mutable: `mut i`...7 | i = 99; | ^^^^^^ cannot assign twice to immutable variable--> test.rs:5:5 |4 | let s = String::from("hello"); | - help: consider changing this to be mutable: `mut s`5 | s.push_str(" world!!!"); | ^ cannot borrow as mutable 2pub fn push_str(&mut self, string: &str) { self.vec.extend_from_slice(string.as_bytes())}(Scalar types)使let f = true;let sum:i32 = 100;let heart_eyed_cat = '';(Compound types)let t: (i32, bool) = (100, false);let (x, y) = t; // let x = t.0; // 访let a = [1, 2, 3];let a: [i32; 5] = [1, 2, 3, 4, 5]; // let b = [10; 5]; // 105使vector6 | let b = [100; 5]; | - help: consider changing this to be mutable: `mut b` 37 | b[1] = 1024; | ^^^^^^^^^^^ cannot assign --> hell.rs:11:23 |11 | let a: [i32; 3] = [1]; | ^^^ expected an array with a fixed size of 3 elements, found one with 1 element访使fnfn foo(i: i32, j: i32) { let sum = i + j}// fn sum(i: i32, j: i32) -> i32 { i + j}let fn_s = sum;let s = fn_s(i, j);let a = { e + 10};println!("{}", a);ifif e % 2 == 0 { // if println!("{}", e);} else if e % 3 == 0 { // println!("{} % 3 ==0", e);} else { println!(":p");} 4使let a = if condition { 5} else { 6};looplet mut i = 0;loop { i += 1; println!("->{}", i);}breaklet s = loop { i += 1; println!("->{}", i); if(i > 100) { break i; }};println!("s = {}", s); // s = 101loop使whileforwhile i < 1000 { // i += 1;}for e in a.iter() { // 使for println!("{}", e); }// for i in (1..10).rev()// 使rev()for i in (1..10) { println!("{}", i);} rust5rust使使线let foo_bar = 1;fn print_info() {}

HTML view coming soon.

Download PDF for the full formatted version.