Â
Rustã®åªããæ§è½ã¨C++ã¨ã®æ¯è¼
Rustã¯ãã®ããã©ã¼ãã³ã¹ã®é«ãã§ã注ç®ããã¦ãã¾ããC++ã«å¹æµããå®è¡é度ãæã¡ãªãããããå®å ¨ã§ç°¡æ½ãªè¨è¨ãæä¾ããç¹ãç¹å¾´ã§ãã以ä¸ã§ã¯ãRustã®é«éæ§ã¨ãC++ã¨æ¯è¼ããéã®åªä½æ§ã«ã¤ãã¦è©³ãã説æãã¾ãã
Rustã®é«éãªããã©ã¼ãã³ã¹
Rustã¯ãã¡ã¢ãªå®å ¨æ§ã確ä¿ãã¤ã¤ãé常ã«é«ãããã©ã¼ãã³ã¹ãèªãã¾ãã以ä¸ã®è¦ç´ ãRustã®ããã©ã¼ãã³ã¹ãæ¯ãã¦ãã¾ãã
- ã¼ãã³ã¹ãæ½è±¡å
Rustã¯é«ã¬ãã«ã®æ½è±¡åãæä¾ãã¤ã¤ããã®æ½è±¡åãå®è¡æã®ãªã¼ãã¼ããããçãããã¾ãããä¾ãã°ã`Iterator`ã`Option`ãªã©ã®åã¯ãé«åº¦ãªæ©è½ãæä¾ããªããããC++ã«å¹æµããé度ã§åä½ãã¾ããããã¯ãRustãã³ã³ãã¤ã«æã«æé©åãè¡ããããå®è¡æã«ä½è¨ãªè² æ ããããªãããã§ãã - éçã¡ã¢ãªç®¡ç
Rustã¯ææ権ã·ã¹ãã ã«ãã£ã¦ãã¡ã¢ãªã®ç®¡çãã³ã³ãã¤ã«æã«è¡ãã¾ããããã«ãããã¬ãã¼ã¸ã³ã¬ã¯ã·ã§ã³ãæåã®ã¡ã¢ãªè§£æ¾ãå¿ è¦ãªããã¡ã¢ãªãªã¼ã¯ãäºé解æ¾ã®ãªã¹ã¯ãæé¤ãã¦ãã¾ãããã®èªåã¡ã¢ãªç®¡çããããã©ã¼ãã³ã¹ãç¶æãã¤ã¤å®å ¨æ§ãæ ä¿ãã¾ãã - æé©åãããã³ã¼ãçæ
Rustã®ã³ã³ãã¤ã©ï¼`rustc`ï¼ã¯ãLLVMãããã¯ã¨ã³ãã¨ãã¦ä½¿ç¨ãã¦ãã¾ãããã®æé©åæè¡ã«ãããçæãããã³ã¼ãã¯é常ã«å¹ççã§ãããC++ã«å¹æµããããã©ã¼ãã³ã¹ãå®ç¾ãã¾ãã - 並åå¦çã®æé©å
Rustã®ææ権ã·ã¹ãã ã¯ä¸¦è¡å¦çã«ããã¦ãé常ã«å¹æçã§ãããã¼ã¿ç«¶åãé²æ¢ããè¨è¨ã«ãããå®å ¨ãã¤å¹ççã«ä¸¦åå¦çãè¡ããã¨ãã§ãã¾ããããã«ãããã¹ã¬ããéã§ã®ãã¼ã¿å ±æãé常ã«å¹çããè¡ããããã©ã¼ãã³ã¹ãåä¸ãã¾ãã
C++ã¨Rustã®æ¯è¼
Rustã¯ãC++ã®å¼·åãªæ©è½ãç¶æ¿ãã¤ã¤ãè¨èªè¨è¨ãæ´çããã¦ããã使ãããããåä¸ãã¦ãã¾ããC++ã¯ãã®è¤éãªè¨èªä»æ§ããå¦ç¿ã³ã¹ããé«ãã¨ãã課é¡ãããã¾ããããRustã¯æ¬¡ã®ããã«ãããæ¹åãã¦ãã¾ãã
- ã¡ã¢ãªç®¡ç
C++ã§ã¯æåã§ã¡ã¢ãªã管çããå¿ è¦ãããã誤ã£ã管çãããã©ã¼ãã³ã¹ãå®å ¨æ§ã«å½±é¿ãä¸ãããã¨ãããã¾ããä¸æ¹ãRustã¯ææ権ã¨åç¨ã®ã«ã¼ã«ã«åºã¥ãèªåã¡ã¢ãªç®¡çãæä¾ããã¡ã¢ãªå®å ¨æ§ãã³ã³ãã¤ã«æã«ç¢ºä¿ãã¾ãã - åã·ã¹ãã
Rustã®åã·ã¹ãã ã¯ãC++ãããå³æ ¼ã§ãããã³ã³ãã¤ã«æã«å¤ãã®ã¨ã©ã¼ãæ¤åºãããã¨ãã§ãã¾ãããã®ã·ã¹ãã ã«ãããå®è¡æã¨ã©ã¼ãé²ããã³ã¼ãã®ä¿¡é ¼æ§ãåä¸ãã¾ãã - 並è¡å¦çã®ç°¡ç´ å
C++ã§ã¯ã¹ã¬ãã管çãè¤éã§ããã競åç¶æ ãåæã®åé¡ãçºçããããã§ãããRustã¯ãã¼ã¿ç«¶åãé²æ¢ããä»çµã¿ãè¨èªã¬ãã«ã§ãµãã¼ããã¦ããã並è¡ããã°ã©ãã³ã°ãå®å ¨ãã¤ç°¡åã«è¡ããã¨ãã§ãã¾ãã - ã¨ã©ã¼å¦ç
C++ã§ã¯ä¾å¤å¦çã使ç¨ãã¾ãããRustã¯`Result`åã¨`Option`åãç¨ããå¼·åãªã¨ã©ã¼å¦çæ©æ§ãæä¾ããã¨ã©ã¼ãããå®å ¨ãã¤å¹ççã«å¦çãã¾ãã - ã©ã¤ãã©ãªç®¡ç
C++ã§ã¯ã©ã¤ãã©ãªã®ç®¡çãåå¥ã®ããã¸ã§ã¯ããã¨ã«è¡ããã¾ãããRustã§ã¯`Cargo`ãç¨ãã簡便ãªããã±ã¼ã¸ç®¡çã·ã¹ãã ãæä¾ããä¾åé¢ä¿ããã«ãããã»ã¹ã®ç®¡çãèªååããã¦ãã¾ãã
Rustã®ä½¿ãããã
Rustã¯ãC++ã®è¤éãªä»æ§ãæ´çãã使ãããããå¤§å¹ ã«åä¸ããã¾ãããRustã使ãéã«é常ã«ä¾¿å©ãªç¹å¾´ã¨ãã¦ã次ã®ãããªç¹ãããã¾ãã
- Cargo
Rustã®ããã±ã¼ã¸ç®¡çãã¼ã«ã§ããCargoã¯ãä¾åé¢ä¿ã®ç®¡çããã«ãããã»ã¹ãèªååããéçºè ã®è² æ ã軽æ¸ãã¾ãã`cargo build`ã`cargo run`ã使ããã¨ã§ãç°¡åã«ããã¸ã§ã¯ãã管çã§ãã¾ãã - ã³ã³ãã¤ã©ã®ã¨ã©ã¼ã¡ãã»ã¼ã¸
Rustã®ã³ã³ãã¤ã©ã¯é常ã«è©³ç´°ã§ããããããã¨ã©ã¼ã¡ãã»ã¼ã¸ãæä¾ãã¦ãããã¨ã©ã¼ãçºçããå ´åã«ã¯åé¡ã®åå ãè¿ éã«ç¹å®ããä¿®æ£ãå©ãã¦ããã¾ãã - æ¨æºã©ã¤ãã©ãª
Rustã®æ¨æºã©ã¤ãã©ãªã¯é常ã«æ´ç·´ããã¦ãããæ¥å¸¸çãªããã°ã©ãã³ã°ã¿ã¹ã¯ãå¹ççã«ããªãããã®ãã¼ã«ãæã£ã¦ãã¾ãã
çµè«
Rustã¯ãC++ã®å¼·åãªæ©è½ãæ´»ããã¤ã¤ããã®è¤éããåãé¤ãã¦æ´çãããä»æ§ã¨ä½¿ãããããæä¾ããã次ä¸ä»£ã®ã·ã¹ãã ããã°ã©ãã³ã°è¨èªã§ããã¡ã¢ãªå®å ¨æ§ã並è¡å¦çã®å®å ¨æ§ãããã¦ããã©ã¼ãã³ã¹ã«ããã¦ãC++ãè¶ ããããã³ã·ã£ã«ãç§ãã¦ãã¾ããããã«ãããç¾ä»£ã®ã½ããã¦ã§ã¢éçºã«ããã¦é常ã«ææãªé¸æè¢ã¨ãªã£ã¦ãããã¨ã¯ééãããã¾ããã