2017-06-01ãã1ã¶æéã®è¨äºä¸è¦§
Rustã®æå¾ åã¯ä»¥ä¸ã®ãããªãã¼ã¿æ§é ã«ãªã£ã¦ããã #[derive(Copy, Clone, Debug)] pub enum Expectation<'tcx> { NoExpectation, ExpectHasType(Ty<'tcx>), ExpectCastableToType(Ty<'tcx>), ExpectRvalueLikeUnsized(Ty<'tcx>), } ãã®ããã«4ã¤ã®ã³ã³â¦
以åã®è¨äºã§èª¬æããããã«ãRustã§ã¯åå¼·å¶ãæ´æ°ãªãã©ã«ãªã©ã®ç¹æ®ãªåæ¨è«ãã·ã¼ã ã¬ã¹ã«è¡ãããã«æå¾ åã¨ããæ¦å¿µãå°å ¥ãã¦ããã ãã®æå¾ åã¯ããããã¦ã³ã«ä¼æ¬ãããããå ã»ã©ã®è¨äºã§æããä¾ fn main() { let x : Box<[_]> = Box::new([1, 2â¦
æ¦è¦: ååã¨ã㦠x + y 㯠::std::ops::Add(x, y) ã®æ§æç³è¡£ã§ããããåæ¨è«ã§ç¹å¥æ±ããããã æ¼ç®åã®è±ç³ æ¼ç®åã®è±ç³ã¯åæ¨è«ã®å¾ãHIRããMIRã¸ã®å¤æã®ã¿ã¤ãã³ã°ã§è¡ããããååã¨ã㦠x + y 㯠::std::ops::Add(x, y) ã®æ§æç³è¡£ã§ãããããâ¦
ãã¿ã¼ã³ããããæã¤è¨èªã§ã¯ãå¤æ°æç¸ã¨ã³ã³ã¹ãã©ã¯ã¿/å®æ°ãæ§æä¸ææ§ã§ããå ´åããããRustã§ã¯ä»¥ä¸ã®è¦åã«å¾ã£ã¦ããã 以ä¸ã®ããã«ãæ§æçã«ãã¹ã§ããã¨ãããå ´åã¯ã常ã«ã³ã³ã¹ãã©ã¯ã¿/å®æ°ã¨ã¿ãªãã :: ãå«ãã§ããå ´åã (::A, self::Aâ¦
Rustã§ã¯ use std; ã use rand; ã®ãããªã¤ã³ãã¼ããå¿ è¦ãªå ´åã¨ãéã«æ¸ãã¨ã¨ã©ã¼ã«ãªãå ´åãããã ç°¡åã«è¨ã㨠ãããã¬ãã«ã¢ã¸ã¥ã¼ã«ã§ã¯ãæ¸ãã¨ã¨ã©ã¼ã«ãªã(æ¢ã«ããååã¨è¡çªãã)ããã以å¤ã®å ´æã§ã¯ãå¿ è¦ãªå ´åãããã ããã¯ååããâ¦
Rustã§ã¯ unsafe ã®è¡¨æãè¡ããªãéãæªå®ç¾©åä½ãçºçããªããã³ã³ãã¤ã©ãè¨èªä»æ§ã®ãã¹ã«ããæªå®ç¾©åä½ãçºçãããå ´åã«ã¯åªå çã«ä¿®æ£ãããã(ãªããæ´æ°ãªã¼ãã¼ããã¼ã®ããã«ç¹å®æ¡ä»¶ä¸ã§ã¨ã©ã¼ã«ãªããã®ã§ãã£ã¦ããæ£ããunwind/abortã§ããâ¦
Rustã³ã³ãã¤ã©ã¯å梱ã®rustbuildã¨ãããã¼ã«ã§ãã«ãããããããã¯Rustã¨Python2ã§æ¸ããã¦ããã README.md ã«ã説æãæ¸ããã¦ããããããã§æ¹ãã¦èª¬æããã¦ã¿ãã ./x.py 㯠src/bootstrap/bootstrap.py ã«ãªã³ã¯ããã¦ãããããã¯æ¬¡ã®ãããªåä½ãâ¦
ã³ã³ãã¤ã©ã®åä½ã調ã¹ãã«ããã£ã¦ããã¡ãã¡masterããã«ãããã®ã¯ä¸ä¾¿ãªã®ã§ãå®å®çã®èªåãã«ããä½æãããã¨ã«ããã $ wget https://static.rust-lang.org/dist/rustc-1.18.0-src.tar.gz $ tar xvf rustc-1.18.0-src.tar.gz $ cd rustc-1.18.0-srcâ¦
Vec<Result<_>> ã§ã¯ãªã Result<Vec<_>> ãå¾ã collect() é¢æ°ã使ãã¨ã Vec<Result<_>> ãå¾ããã¨ãã§ãããã Result<Vec<_>> ãå¾ããã¨ãã§ãããå¤æå ã®åãæ示ãããã¨ã§åºå¥ããã fn main() { // å ¨ã¦SomeãªãSome(é å)ãè¿ããã©ãããNoneãªãå ¨ä½ãNoneã«ãªã assert_eq!([So</vec<_></result<_></vec<_></result<_>â¦
Rustã®ãã¿ã¼ã³ãããã¯ç¶²ç¾ æ§ãæ¤æ»ãããç¶²ç¾ çã§ãªãå ´åã¯ã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªããç¶²ç¾ æ§ã¯ä»¥ä¸ã®ããã«æ¤è¨¼ãããã åã®åé¡ ãã¿ã¼ã³ãããã®ç¶²ç¾ æ§ãããã¨ãã«ã¯ãå ¨ã¦ã®åãADTã®ããã«æ±ããããã¤ã¾ããæéåã®å¼æ°ãã¨ãã³ã³ã¹ãã©ã¯ã¿ãæéâ¦
Rustã® match ã®è ã¯ã«ã³ãã§åºåããããããããçç¥ã§ããå ´åã2ã¤ããã æ«å°¾ã®ã«ã³ã => { .. } ã®ç´å¾ã®ã«ã³ã fn main() { match Some(1) { Some(x) => { } // => { .. } ã®ç´å¾ã«ã¯ã«ã³ãã¯çç¥å¯è½ None => () // æ«å°¾ã®ã«ã³ãã¯çç¥å¯è½ } } ãã®â¦
ç¾å¨ã®å®å®çã§ã¯ç¡å¹åããã¦ããããRustã®beta/nightlyã«ã¯æ§é ä½/åæåãã£ã¼ã«ãã®èªå並ã¹æ¿ããå®è£ ããã¦ããããã®åä½ã説æããã ä¾ ä»¥ä¸ã®ãããªããã°ã©ã ãæ¸ãã¨ãç¾å¨ã®å®å®çã§ã¯6ã表示ãããbeta/nightlyã§ã¯4ã表示ãããã use std::â¦
æ¦è¦: Rustã®ä¸å®å®æ©è½ã§ããé ç½®æ§æã¨boxæ§æã®ä»çµã¿ã説æããã é ç½®æ§æã®åæ© Rustã®å¤æ¸¡ãã¯ããã©ã«ãã§ã ã¼ãã§ãããã³ãã¼ã³ã³ã¹ãã©ã¯ã¿ã¼ã®ãããªéãå¦çãåæã«å®è¡ããããã¨ã¯ãªããããå¤ãã®å ´é¢ã§ã¯å¤æ¸¡ãã®ã³ã¹ãã¯ããã»ã©é«ããªãâ¦
æ¦è¦: Rustã®åæ¨è«ã®å¤§æ ã説æããã ãªããçè ãRustã®åæ¨è«ã®åä½ã詳細ã«ææ¡ãã¦ããããã§ã¯ãªãã çãã¾ã¨ãã㨠Rustã®åæ¨è«ã¯Hindley-Milneråæ¨è«ãã¼ã¹ã§ããããããã£ã¦å¾æ¹ã®å¼ãæã®å 容ããæåã®åãæ¨è«ããããã¨ããããããã以ä¸â¦
Rustã®nightlyã«æ°ããå ¥ã£ãtry-catché¢é£æ§æãç´¹ä»ããã do catch ã«ããcatchæ§æ #![feature(catch_expr)] use std::fs::File; use std::io::{self, BufReader, Read}; fn main() { do catch { let f = File::open("foo.txt")?; let mut f = BufReaderâ¦
æ¦è¦: Rustã® derive ã¯ãã¾ãé ããããªãã derive ããã¸ãè¸ãä¾ derive ã®åé¡ã¯é¡å¨åãããããRustã³ã³ãã¤ã©ã®GitHubä¸ã§ãä½åº¦ãéè¤ããissueãæãããã¦ãããä»ã¯ä¸»ã« #26925 ãä¸å¿ã«è°è«ãã¾ã¨ã¾ã£ã¦ããã®ã§ããã¡ããåç §ããã¨ããã ããâ¦