入门安装Rust在linux和mac上安装rustup$curl--proto'=https'--tlsv1.2https://sh.rustup.rs-sSf|如果安装成功,sh将显示Rust现在已安装。伟大的!在Windows上安装rustup数据类型字符conststr="hello";conststring=String("hello");//字符合并constlongString="a"+"b";Rust///stringletstr="hello";letstring=String::from("hello");///characterletch='h';//characterconvertedtostringletstr1=ch.to_string().as_str();//合并字符letlong_string=String::from("a").push('b');Numberjavascript只有number类型,不区分浮点数和整数。typeofNaN==='number'Rust区分有符号数、浮点数和整数。数组Javascriptconstarray=[];array.push(1);constlen_array=[1,2,3];consta=len_array[0];Rustletarray=vec![];//这里数组的长度已经确定了letlen_array:[i32,3]=[1,2,3]leta=len_array[0];objectRust使用struct来实现类,使用赋值Javascriptletword='a';word='b';Rustletmutword='a';单词='b';String中使用所有权lets1=String::from("hello");lets2=s1;//errorprintln!("{},world!",s1);可以通过克隆和引用指针来解决。所有权的概念是为了解决doublefreeJavascript的错误流控循环和条件判断while(letch=next()){if(ch==='\n'||ch==='\r'||(真&&真)){中断;}elseif(ch==='\t'){//做点什么}else{//做点什么}}Rustloop{letch=next()ifch=='\n'||ch=='\r'||(真&&真){中断;}elseifch==='\t'{//dosomething}else{//dosomething}}三对象操作Javascriptconsta=true?1:2;Rustleta=iftrue{1}else{2}EngineeringcargoReadme
