RUST in an hour
Delete element
The underscore is a special name - or rather, a “lack of name”. It basically means to throw away something:_
// this does *nothing* because 42 is a constant
let _ = 42;
// this calls `get_thing` but throws away its result
let _ = get_thing();
Tuples
the format of tuples is “(a,b,c…)” , the most usage are similar to tuples in Python:
let pair = ('a', 17);
pair.0; // this is 'a'
pair.1; // this is 17
//you can define their type
let pairs:(i32, i32,char) = (1,2,'a');
the content of tuples are static
Distructuring tuples
example:
let (x, y, z) = (1, 2, 3);
Statements
let x = vec![1, 2, 3, 4, 5, 6, 7, 8]
.iter()
.map(|x| x + 3)
.fold(0, |x, y| x + y);