rust基本语法与常用功能总结

rust基本语法与常用功能总结

hello world!

fn main(){
    print!("hello,world!");//不换行
    println!("Hello, world!");//换行
}

数据类型及变量定义

基础数据类型

    let a:i8 = 1;
	let a:i16 = 1;//同一变量名,重新绑定
	let a:i32 = 1;
	let a:i64 = 1;
	let a:i128 = 1;
	let a:u8 = 1;
	let a:u16 = 1;
	let a:u32 = 1;
	let a:u64 = 1;
	let a:u128 = 1;
	let a:f32 = 1.0;
	let a:f64 = 1.0;
	let a:bool = false;
	let a:char = 'a';
	let a:String = "string".to_string();
    let a:&str = "string";
    let a:String = String::from("string");

数组

let y=[1,2,3];  //[i32;3] 不可变数组长度3,推断类型i32 
let z:[u8;3]=[1,2,3]; //声明定长不可变数组
let a1=[1..

你可能感兴趣的:(rust学习,rust)