-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
37 lines (30 loc) · 952 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
*
* 基本数据类型
* https://doc.rust-lang.org/rust-by-example/primitives.html
*/
fn main() {
let logical: bool = true;
println!("logical:{}", logical);
let a_float: f64 = 1.0; // 常规类型注释
let an_integer = 5i32; // 后缀注释
println!("a_float,an_integer: {:.1} {}", a_float, an_integer);
let default_float = 3.0; // f64
let default_integer = 7; // i32
println!(
"default_float,default_integer: {:.1} {}",
default_float, default_integer
);
let mut inferred_type = 12; // 自动推断 i64
println!("inferred_type: {}", inferred_type);
inferred_type = 4294967296i64;
println!("inferred_type: {}", inferred_type);
let mut mutable = 12; // i32
println!("mutable: {}", mutable);
mutable = 21;
println!("mutable: {}", mutable);
//mutable = true; // error
// 类型覆盖
let mutable = true;
println!("mutable: {}", mutable);
}