ã¯ããã«
ãååã¯ããTauri 2.0ãã¨ãRustãã«ã¤ãã¦ã®åºæ¬æ å ±ã¨ç°å¢æ´åã解説ãã¾ãããä»åã¯ãå®éã«ãçµµæãã¢ããªãä½ãåã«ãã¾ãRustã®ææ³ã«ã¤ãã¦ãããããã¦ããã¾ããããããRustã®ææ³ããããåç¥ãªãããã®åã¯èªã¿é£ã°ãã¦ã大ä¸å¤«ã§ããç¹å¥ãªãã¨ã¯æ¸ãã¦ãã¾ããã
ããã ãããã°ã©ãã³ã°è¨èªãC/C++ããç¥ã£ã¦ãã¦ããRustã«ã¯ææ権ã¨ããç¬ç¹ãªã¡ã¢ãªç®¡çã®æ¦å¿µãããã®ã§ãRustãåãã¦ã®æ¹ã¯å¿ ãèªãã§ãã ããããnewãããdeleteãã¨ã¯ä¸å³éãã¾ãã
Rustã®ç¥ã£ã¦ããã¹ãææ³
ãããã°ã©ãã³ã°è¨èªã«ããã¦ãæãåºæ¬ã§æãéè¦ãªææ³ã®1ã¤ããå¤æ°ãã§ãã
ãå¤æ°ã«ã¯å¤ãå ¥ãããè¦ããå¾ããå¤ãä¸æ¸ãããããããã¨ãã§ãã¾ããå¤æ°ã«å ¥ããããå¤ã«ã¯ããã¼ã¿åãã¨ãã種é¡ã決ãããã¦ãã¾ããæ°å¤ã®å¤æ°ã¯ç®æ°ã¨åãè¨ç®ãã§ãã¾ããã¾ãããã°ã©ã ã®å¦çãã¾ã¨ãã¦ãé¢æ°ãã«ã§ãã¾ãã
ããã®é£è¼ã§ã¯ä½¿ããªãã®ã§è§£èª¬ãã¾ãããããè¾æ¸åãã¨ããææ³ãããã¾ãããã®åã®éãè¾æ¸ã§åèªã調ã¹ãã¨åèªã®æå³ãåããã®ã«ä¼¼ã¦ãã¾ãã
å¤æ°
ã次ã®ãµã³ãã«ã³ã¼ãã®ããã«æ¸ãã¨ä¸ããé ã«ããã°ã©ã ãå®è¡ããã¦ã¿ã¼ããã«ã«"i=1975"ã¨ããæååã表示ããã¾ãããletãã§ãiãã¨ããå¤æ°ã«ã1975ãã¨ããæ°å¤ãã=ãã§ä»£å ¥ãã¾ããå¤ãã®ããã°ã©ãã³ã°è¨èªã«ããã¦ã=ãã¯ãçå·ãã§ã¯ãªããä»£å ¥ããæå³ããä»£å ¥æ¼ç®åãã¨è¨ãã¾ãã
ããprintln!ãã¯ããã¯ããã¨ãããã®ã§ãããã§ã¯æååãã¿ã¼ããã«ã«è¡¨ç¤ºããæ©è½ãæã¤ãã®ã ã¨ç解ãã¦ãã ããã""ã§å²ã¾ããæååãã¿ã¼ããã«ã«è¡¨ç¤ºããã¾ãã{}ã®é¨åã«iã®å¤ãå·®ãè¾¼ã¾ãã¾ãã
fn main() { let i = 1975; println!("i={}",i); }
ãã¼ã¿å
ããã¼ã¿åã®ç¨®é¡ã®è¡¨ãè¦ãåã«ã次ã®ãµã³ãã«ã³ã¼ããè¦ã¦ãã ãããåã®ãµã³ãã«ã¨éã£ã¦ãlet b1:boolãã¨å¤æ°ã«ã: boolããã¤ãã¦ãã¾ãããboolãã«ã¯ãtrueãããfalseãã ããä»£å ¥ã§ãããã®åããã¼ã¿åã§ãã
fn main() { let b1: bool = true; println!("b1={}",b1); let i1: i8 = 123; println!("i1={}",i1); let u1: u16 = 12345; println!("u1={}",u1); let i2: i32 = 1234567890; println!("i2={}",i2); let u2: u64 = 1234567890123456789; println!("u2={}",u2); let f1: f32 = 0.12345678; println!("f1={}",f1); let f2: f64 = 0.1234567890123456; println!("f2={}",f2); let s1: char = 'å'; println!("s1={}",s1); let s2: &str = "æåå1"; println!("s2={}",s2); let s3: String = "æåå2".to_string(); println!("s3={}",s3); }
ãã§ã¯ããã¼ã¿åã®ç¨®é¡ã®è¡¨ãè¦ã¦ãã ãããã符å·ãªããã¨ããã®ã¯ãæ£ã®æ´æ°ãã§ããæ¸ãã¦ã¯ãã¾ãããã符å·ãããã®æ´æ°ã¯æ£è² 両æ¹ã®æ´æ°ã§ãã
ããf32ãã¨ãf64ãã¯ãæµ®åå°æ°ç¹ãã¨è¨ããã¾ãããæ´æ°ãå«ã¾ããã®ã§ãå®æ°ãã¨èª¬æãã¾ããããããã使ããæ°å¤ã®ç¯å²ãç°ãªãã¾ããã¾ãå¿ ã1æåã®ãcharãåã¨ã0ãè¤æ°æååã®ãstrãåãããã¾ãã
ãã¼ã¿å | 説æ |
---|---|
boolå | trueã¨falseã®çå½å¤ |
u8å | 8bitã®0ï½255ã®ç¬¦å·ãªãæ´æ° |
u16å | 16bitã®0ï½65535ã®ç¬¦å·ãªãæ´æ° |
u32å | 32bitã®0ï½4294967295ã®ç¬¦å·ãªãæ´æ° |
u64å | 64bitã®0ï½18446744073709551615ã®ç¬¦å·ãªãæ´æ° |
usizeå | 32bitã¨64bitã®0ï½18446744073709551615ã®ç¬¦å·ãªãæ´æ° |
i8å | 8bitã®-128ï½127ã®æ´æ° |
i16å | 16bitã®-32768ï½32767ã®æ´æ° |
i32å | 32bitã®-2147483648ï½2147483647ã®æ´æ° |
i64å | 64bitã®-9223372036854775808ï½9223372036854775807ã®æ´æ° |
isizeå | 32bitã¨64bitã®-9223372036854775808ï½9223372036854775807ã®æ´æ° |
f32å | 32bitã®-3.4028235e38ï½3.4028235e38ã®å®æ°(ãeãã¯ãæµ®åå°æ°ç¹å®æ°ã) |
f64å | 64bitã®-1.7976931348623157e308ï½1.7976931348623157e308ã®å®æ° |
charå | 1æåã®ã¦ãã³ã¼ãæå |
strå | ã¦ãã³ã¼ãæåå |
æ¼ç®å
ã次ã®ãµã³ãã«ã³ã¼ãã®ããã«åºæ¬çãªè¨ç®ã¯ãå æ¸ä¹é¤ãã¨ãå°ä½ãã ãã§ããå°ä½ã¨ã¯ãé¤ç®ããä½ãã®ãã¨ã§ããããããçµã¿åãããã°3DCGãªã©ã®è¤éãªè¨ç®ãã§ãã¦ãã¾ãã¾ãã
ããå ç®ãã¯ã+ãããæ¸ç®ãã¯ã-ãããä¹ç®ãã¯ã*ãããé¤ç®ãã¯ã/ãããå°ä½ãã¯ã%ãã®è¨å·ã§è¨ç®ãã¾ãããããããç®è¡æ¼ç®åãã¨è¨ãã¾ããã»ã¨ãã©ç®æ°ãã®ã¾ã¾ã§ãããæ°å¦ãçªãè©°ããã°ãããã®ç®æ°ã®è¨ç®ã ãã§ã§ããã®ã¨åããã¨ã§ãã
ãã¾ãå ç®ã¨ä»£å ¥ãåæã«ããã«ã¯ã+=ããæ¸ç®ã¨ä»£å ¥ãåæã«ããã«ã¯ã-=ããä¹ç®ã¨ä»£å ¥ãåæã«ããã«ã¯ã*=ããé¤ç®ã¨ä»£å ¥ãåæã«ããã«ã¯ã/=ããå°ä½ã¨ä»£å ¥ãåæã«ããã«ã¯ã%=ãã使ãã¾ãããããããè¤åä»£å ¥æ¼ç®åãã¨è¨ãã¾ãã
fn main() { let i1 = 9 + 8; println!("i1={}",i1); let mut i2 = i1 - 7; // å¾ã§å¤ãå¤æ´ãããã®ã§ãmutããä»ãã println!("i2={}",i2); let i3 = i2 * 6; println!("i3={}",i3); let i4 = i3 / 5; println!("i4={}",i4); let i5 = i4 % 4; println!("i5={}",i5); i2 += i3; println!("i2={}",i2); }
é å
ã次ã®ãµã³ãã«ã³ã¼ãã®ããã«è¤æ°ã®å¤æ°ã1ã¤ã«ã¾ã¨ãã¦æã¦ããã®ããé åãã§ããé åã¯ãlet é åå = [å¤1,å¤2,]ãã¨å®£è¨ãããé åå[ã¤ã³ããã¯ã¹çªå·]ãã§å¤ãä»£å ¥ãããå¤ãè¦ããã§ãã¾ãã
é åã®ææ³
let mut é åå = [å¤1,å¤2,ã»ã»ã»];
é åå[ã¤ã³ããã¯ã¹çªå·] = å¤3;
let å¤æ° = é åå[ã¤ã³ããã¯ã¹çªå·];
ãä»åã¯çç¥ãã¾ãããé åã«ããä¼¼ãææ³ã§ãã¿ãã«ãã¨ããææ³ãããã¾ããé åã®è¦ç´ ã¯å ¨ã¦åããã¼ã¿åã®å¤æ°ãæããªããã°ãªãã¾ããããã¿ãã«ã¯ç°ãªããã¼ã¿åã®è¦ç´ ãæã¤ãã¨ãã§ãã¾ãã
fn main() { let mut arr = ["éç","ãã¼ã«ãã³","ä¸å¹´ç"]; // å¾ã§å¤ãå¤æ´ãããã®ã§ãmutããä»ãã println!("{}",arr[0]); println!("{}",arr[1]); arr[2] = "ã¬ã©ã¹ãã³"; println!("{}",arr[2]); }
é¢æ°
ã説æãé ãã¾ãããããfn main()ãã¯é¢æ°ã宣è¨ãã¦ãã¾ããmainé¢æ°ãããã°ã©ã èµ·åæã«æåã«å¼ã°ããããã«ç¶ã{ã¨}ã®ã¹ã³ã¼ãå ã®å¦çãå®è¡ãã¾ããããã¦æ¬¡ã®ãµã³ãã«ã³ã¼ãã®ããã«mainé¢æ°ä»¥å¤ã«ãé¢æ°ãä½ããã¨ãã§ãã¾ãã
ãããã§ã¯ãfuncãé¢æ°ã宣è¨ãããfunc(2024)ãå¼ã°ããã¨ãhikisuãå¼æ°ã¨ãã¦2024ã渡ããããformat!ããã¯ãã§"ã¨"å ã®æååããmodoritiãå¤æ°ã«ä»£å ¥ãã¾ããé¢æ°ããå¤ãè¿ãå¤ããæ»ãå¤ãã¨è¨ãã¾ããmodoritiæ»ãå¤ã¯ãreturn modoriti;ãã¨æ¸ãã¦ãæ£ããã§ãããã åè ã®æ¹ãã³ã¼ãéãå°ãªããªãåãè¦ãç®ãã¨ã¬ã¬ã³ãã§ãã
é¢æ°ã®ææ³
fn é¢æ°å(å¼æ°1: ãã¼ã¿å,å¼æ°2: ãã¼ã¿å,ã»ã»ã») -> æ»ãå¤ {
ã¹ãã¼ãã¡ã³ã
æ»ãå¤
}
fn main() { let s = func(2024); println!("{}",s); } fn func(hikisu:usize) -> String { let modoriti = format!("hikisu={}",hikisu); modoriti }