Rustã®åºæ¬åã®ã¡ã½ããã¯ã©ãã§å®ç¾©ããã¦ããã
æ¦è¦: Rustã®åºæ¬åãã®ãã®ã¯ã³ã³ãã¤ã©ã§ç¹å¥ã«å®ç¾©ããã¦ãããã§ã¯åã«é¢é£ã¥ããããã¡ã½ããã¯ã©ãã«ããã®ãã
åºæã¡ã½ããã®ããã
åºæã¡ã½ãã㯠core
ã®åæã§å®ç¾©ããã¦ãããä¾ãã° i32
ã®åºæå®è£
㯠core::num
ã«å®ç¾©ããã¦ããã
#[lang = "i32"] impl i32 { ... }
ããã§ã #[lang = "i32"]
ã«æ³¨æããå¿
è¦ããããåºæ¬åã®åºæå®è£
ã«ã¯ããããlang item markerãå²ãå½ã¦ããã¦ãããå®éã®åºæã¡ã½ãã解決ã¯ãã®lang item markerçµç±ã§è¡ããã¦ããããã§ããã
ãªããæ°å¤å以å¤ã®åºæ¬åã®åºæå®è£ ã¯ä»¥ä¸ã®å ´æã«å®ç¾©ããã¦ããã
char
…std_unicode::char
ã«å®ç¾©ããã¦ãããstr
…collections::str
ã«å®ç¾©ããã¦ããã[T]
…collections::slice
ã«å®ç¾©ããã¦ããã*const T
,*mut T
…core::ptr
ã«å®ç¾©ããã¦ããã
ãã¬ã¤ãå®è£ ã®ããã
ãã¬ã¤ãå®è£ ã¯åºæå®è£ ã®ãããªç¹å¥æ±ããåããªããåºæå®è£ ã¨åãããã«åºæ¬åãã¨ã«ã¾ã¨ããããã¢ã¸ã¥ã¼ã«ã§å®ç¾©ãããããåãã¬ã¤ãã®è¿ãã§å®ç¾©ããããã¨ãå¤ãããã§ããã
æ¼ç®åã®ããã
ãã¬ã¤ãå®è£ ã®ãªãã§ããããã¤ãã®æ¼ç®åã®å®è£ ã¯ç¹å¥ãªæ±ããåãããã¨ããã®ããæ¨æºã©ã¤ãã©ãªå ã§ã®åºæ¬åã®æ¼ç®åã®å®è£ ã¯ãããã以ä¸ã®ãããªå½¢ã«ãªã£ã¦ããã®ã§ããã
impl core::ops::Add<i32> for i32 { type Output = i32; fn add(self, other: i32) -> i32 { self + other } }
ããã¯ä¸è¦ããã¨å¾ªç°è«æ³ã§ããããããã§ã¯ãªããå®ã¯è©±ãéã§ãã¦ã¼ã¶ã¼å®ç¾©åã®å ´å㯠+
㯠std::ops::Add
ã®ç³è¡£æ§æã ããåºæ¬åã«ã¤ãã¦ã¯ +
ãçµè¾¼ã¿ã§ããããç¨ã㦠std::ops::Add
ã®å®è£
ãä¸ãããã¦ããã¨ããããã§ããã
å®ã¯ãRust 1.17.0 ã§ã¯ãä¸ã®ãããªå®è£
ããã®ã¾ã¾ç¨ãã¦åæ¤æ»ãè¡ããã¤ã¾ããã®æç¹ã§ã¯å®éã« self + other
㯠<i32 as core::ops::Add<i32>>::add(self, other)
ã¨èªèããã¦ããã
ãã¡ããããã®ã¾ã¾ã³ã¼ãçæã«é²ãã¨ç¡éã«ã¼ããçæããã¦ãã¾ãã®ã§ãåæ¤æ»ã®ãã¨ã«ãã¡ã½ãã解決ã®æ
å ±ãåé¤ãããã¨ã§ã¯ã¼ã¯ã¢ã©ã¦ã³ããã¦ãããããã§åé¤ãããã®ã¯ãã¹ã«ã©ã¼ã«å¯¾ãã1é
æ¼ç®ããã¹ã«ã©ã¼å士ã®2é
æ¼ç®ã§ãããããã§ããã¹ã«ã©ã¼ã¨ã¯ã bool
, char
, æ´æ°ãæµ®åå°æ°ç¹æ°ãé¢æ°ãã¤ã³ã¿ãçãã¤ã³ã¿ã§ããã
æ¼ç®åã¯ã©ãå¤æãããã
ç¶ãã¦ãã¹ã«ã©ã¼ã«å¯¾ããæ¼ç®åã¯ãHIRããHAIRã¸ã®å¤ææã«çµè¾¼ã¿ã®æ¼ç®åã«å¤æãããã
ããã«HAIRã¯MIRã«å¤æãããããã¹ã«ã©ã¼ã«å¯¾ããåºæ¬æ¼ç®ã¯ã©ããå³è¾ºå¤ãçæãããããæçµçã«ã¯ as_rvalue
ã®ãã«ãã¼ã§å¦çãããã
ã³ã¼ããè¦ãã¨ãããããã«ãã¹ã«ã©ã¼ã«å¯¾ããåºæ¬æ¼ç®ã«ãªã¼ãã¼ããã¼ãã§ãã¯ãå ¥ãã®ã¯ãã®ã¿ã¤ãã³ã°ã§ããããªã¼ãã¼ããã¼ãã§ãã¯ãçæããããã©ããã¯æ¬¡ã®åºæºã§æ±ºå®ããã¦ããã
- ã³ã³ãã¤ã©ãªãã·ã§ã³ã§ãªã¼ãã¼ããã¼ãã§ãã¯ãæå¹ã«ããããæå®ãããã ã¾ãã¯
- å®æ°ãè¦æ±ããã¦ããæèã§ããã ã¾ãã¯
#[rustc_inherit_overflow_checks]
ãæå®ãããã
ãã ãã³ã³ãã¤ã©ãªãã·ã§ã³ã¯ä»¥ä¸ã®ããã«è§£éãããã
-C overflow-checks
ãããã°ããã®yesã¾ãã¯noãæ¡ç¨ãããã- ä¸ãæå®ããã¦ãããã
-Z force-overflow-checks
ãæå®ããã¦ããã°ããã®yesã¾ãã¯noãæ¡ç¨ãããã - ä¸ã®ããããæå®ããã¦ããªãå ´åã¯ã
-C debug-assertions
ã®å¤ãæ¡ç¨ãããã
ã¾ã¨ã
Rustã®åºæ¬åã®ãã¡ãåºæå®è£ ã¯lang itemçµç±ã§çºè¦ãããããã¬ã¤ãå®è£ ã¯ä¸è¬çãªä»çµã¿ã使ã£ã¦ããããæ¼ç®åã ãã¯ä¾å¤ã§ãHIRâMIRã¸ã®å¤ææã«çµè¾¼ã¿ã®æ¼ç®ã«å¤æãããã