Rust中变量和函数命名方法是蛇形命名法(小写字母加下划线),而在类和常量一般为首字母大写或者是大写字母。
基本数据类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| let is_bool: bool = true; let is_false = false;
let a = 'a'; let b = '你'; let c = '🐈';
let c: i8 = -111;
let d: f32 = 0.0009;
println!("max = {}",usize::max_value());
|
复合数据类型
数组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
fn main() { let arr: [u32; 5] = [1,2,3,4,5] ; println!("arr[0] = {} ",arr[0]); let arr1: [u32;3] = [1,2,3]; show(arr1); } fn show(array : [u32;3]) { println!("---------------------"); for i in &array { println!("{}",i); } println!("---------------------"); }
|
元组
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| let tup: (i32,f32,char) = (-3,3.69,'好'); println!("{}",tup.0); println!("{}",tup.1); println!("{}",tup.2);
let tup = (-3,3.67,'坏');
let (x,y,z) = tup; println!("{}",x); println!("{}",y); println!("{}",z);
|
枚举
结构体
字符串