Rust

RMAG news

1.baseType in Rust follow
the basical datatypes are as follow

i8 i16 i32 i64 isize //signed integer
u8 u16 u32 u64 usize // unsigned integer
f32 f64 //float datatype
char // Occupies four bytes of unicode
bool
let array:[u16;3] =[1,2,3]; // array database;
/*
* the type of element inner array must be same;
*/
let one= array[0]

//Tuple

let ff:(string,u8,f32) = (“12”,22,2.1221);
let one =ff.0;
let (one,two,three) = ff;
/*
* the type of element inner array does not have to be same

*/

let s =”hello”;
s’s type is &type; &type is splice of type;
if it is string literal like bellow; it store in stack

let s2= String.from(“12321”);
let ff=&s2[0,2];
ff is a reference to s2.it store in head;
let char_count = s.chars().count();
&s2[..] == &s2[0..char_count];
&s2[2..5]
&s2[..5]=&s2[0..5]

let fn2:fn(i32) -> i32 = fn (s:i32) {
x + 1

}

remember x + 1 without ; is expression;
But

x + 1;

is statement end mark
In Rust only expression call default return;

expression as follow

if(x > 5){
10
}else {
20
}

{
let a=10;
let b=10;
a+b
}

fu()

statement as follow

let number = if x > 5 { 10 } else { 0 }; // if 表达式的值被绑定到 number

let z = {
let a = 2;
let b = 3;
a + b // 代码块的值是 5
};

Leave a Reply

Your email address will not be published. Required fields are marked *