immutable slice and borrowed slice
This commit is contained in:
parent
de5218c5dd
commit
4518c489dc
50 changed files with 7 additions and 28 deletions
29
src/main.rs
29
src/main.rs
|
@ -1,26 +1,9 @@
|
|||
fn main() {
|
||||
let mut a: [i8; 10] = [42; 10];
|
||||
a[5] = 0;
|
||||
println!("a: {:?}", a);
|
||||
let a: [i32; 6] = [10, 20, 30, 40, 50, 60];
|
||||
println!("a: {a:?}");
|
||||
|
||||
// so this is assigning an immutable tuple
|
||||
let t: (i8, bool) = (7, true);
|
||||
println!("t 1st: {}", t.0);
|
||||
println!("t 2nd: {}", t.1);
|
||||
|
||||
let pre_ref_x: &mut i32;
|
||||
{
|
||||
let mut x: i32 = 10;
|
||||
let mut z: i32 = 5;
|
||||
println!("x: {x}");
|
||||
println!("z: {z}");
|
||||
let mut ref_x: &mut i32 = &mut x;
|
||||
*ref_x = 20;
|
||||
pre_ref_x = &mut x;
|
||||
println!("x: {x}");
|
||||
ref_x = &mut z;
|
||||
*ref_x = 20;
|
||||
println!("z: {z}");
|
||||
}
|
||||
println!("pre_ref_x: {pre_ref_x}");
|
||||
let s: &[i32] = &a[2..4];
|
||||
println!("s: {s:?}");
|
||||
println!("a[2]: {}", a[2]);
|
||||
println!("s[0]: {}", s[0]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue