æ¦è¦: Rust2018以éãRustã®ã¢ã¸ã¥ã¼ã«ã·ã¹ãã ã¯å ¥éããããããã¤ãã¹ã¿ã¼ãã«ãããªãã¾ãããããã§æ¬è¨äºã§ã¯ããã®ä¸¡æ¹ãéæãããã¨ãç®æãã¾ããã ã¢ã¸ã¥ã¼ã«å ¥é åå解決ã®å½¹å²ã¨ç¨èª ã¢ã¸ã¥ã¼ã«ã°ã©ãã®æ§é ã¤ã³ãã¼ã解決 å¯è¦æ§ ãã¹è§£æ±º åå解決ã¨ãã¯ã æ¬è¨äºã¯2017å¹´ã«æ¸ããè¨äº (https://qnighy.hatenablog.com/entry/2017/03/27/070000, https://qnighy.hatenablog.com/entry/2017/04/24/070000 ) ã¨åããã¼ãã§ãRust2018ãèæ ®ãã¦æ¹ãã¦ã¾ã¨ãç´ãããã®ã§ãã 注æ: æ¬è¨äºä¸ã®ãµã³ãã«ã³ã¼ãã®å¤ãã¯ãRustã®ç´°ããä»æ§ãå®è£ ã調ã¹ãããã®ãã®ã§ãããå®éã«æç¨ãªããã°ã©ãã³ã°ãã¿ã¼ã³ã§ããã¨ã¯éãã¾ãããã¾ããå®è³ªçã«ãã°ã«è¿ãæåã説æãã¦ããã
ã¯ããã« Rust ã®ããã¥ã¡ã³ããèªãã ãå®éã«åãããããã¦ç解ãããã¨ãã¾ã¨ãã¦ããã1ããã¯ãã®èª¬æã ãã§ãããªãé·ããªããããªã®ã§ãï¼ã¤ã®è¨äºã«ãã¦ã¿ã¾ããã ãã¯ãã«ã¯ä»¥ä¸ã®ãã¡ãªããããããããä¸è¬çã«ã¯ãã¾ãå©ç¨ããªãæ¹ãããã¨è¨ããã¾ãã ã³ã¼ããç解ãã¥ãã è¯ããã¯ããæ¸ãã®ã¯é£ãã ã³ã³ãã¤ã«ã¨ã©ã¼ã¯å±éå¾ã®ã³ã¼ãã§èµ·ããã®ã§ãåå ãåããé£ã C/C++ ã®ãã¯ãã¯ã³ã³ãã¤ã©ã¨ã¯å¥ã«ç¨æãããããªããã»ããµã«ãããæ§æã解éããªãåç´ãªæååç½®æãè¡ããã¾ãããã®ãã注æãã¦å©ç¨ããªãã¨æå³ããªãåä½ãèµ·ãããã¨ãããã¾ã2ãä¸æ¹ãRust ã®ãã¯ãã¯ãã®ãããªåé¡ãèµ·ãããªãä»çµã¿ã«ãªã£ã¦ãã¾ãã ãªããâæ¬ç©ã®ãã¯ãâã§Cã®ã³ã¼ãè¡æ°ãååã«ï¼ãã¨ããè¨äºã«ããã°ããProgramming Clojureãï¼Stuart Hallowayèï¼ã«ä»¥ä¸ã®è¦åãæ¸ã
ã¯ããã« å¼ãç¶ã Rust + WebAssembly + SolidJS ã§éãã§ãã¾ãããä»ãåãããã ããããã¨ããããã¾ããååã¾ã§ã§ãä»»æã®ã¡ã¢ãªãããã¡ã確ä¿ãã¦ããã®ä¸ã§ TypedArray ã String ã JSON ãããã¨ãåºæ¥ãæ§ã«ãªã£ãã®ã§ããã2 ç¹ã»ã©æ°ã«ãªã£ã¦ãããã¨ãããã¾ãã æ°ã«ãªã£ã¦ãããã¨â JavaScript å´ã® console ã« Rust å´ããåºåããéã®ã³ã¼ãã§ããããããªæãã«ãªã£ã¦ãã¾ãã ã¾ãã»ã»ã»ããããäºã¯åºæ¥ã¦ããã®ã§ãããconsole::debug ã String ãåãåãä»æ§ã®ããããã¡ãã¡ format! ãã¦æ¸¡ãã«ã¿ãã«ãªã£ã¦ãã¾ãããã°ãåºããããªãã¦æã¯ãããªãã®ç¢ºç㧠{} ã¨ã {:?} ã¨ããããããºãªã®ã§ãå°å³ã«ã¡ã³ãã¦ã»ã»ã»ã¨ãããã¤ã±ã¦ãªãæãããã¾ãã æ°ã«ãªã£ã¦ãããã¨â¡ typed
ä»æ´ã§ããRustã®actix-webã§JWT(JSON Web Token)ã試ãã¦ã¿ã¾ãããJWTã¨ã¯JsonãBase64URLã¨ã³ã³ã¼ãããç½²åãä»ãããã¨ã§æ¹ãããæ¤ç¥ã§ãããããªãã®ã«ãªã£ã¦ãã¾ãããJWTãã¯ããã¼ã«ãã¦æ¸¡ããã¨ã§ãµã¼ããµã¤ãã§ã»ãã·ã§ã³ãä¿æããªãã¨ãããã¨ãã§ããã®ã§ããã2017å¹´ãããã«ãªãªã¼ã¹ãããPlayFramework2.6ã§ãããããã©ã«ãã«ãªã£ãã®ãã¤ã³ãã¯ãããã£ãã®ã§å°è±¡ã«æ®ã£ã¦ãã¾ããJWTã®ã¯ããã¼ã使ããã¨ã§ãµã¼ãéã§ã®ã»ãã·ã§ã³æ å ±ã®åæã¯å¿ è¦ããªããªãã¹ã±ã¼ã«ã¢ã¦ããããããªãã¨ããç¹å¾´ãããããã§ãã JWTã¨ã¯ Rustã§å®è£ ãã¦ã¿ã JWTçºè¡ JWTæ¤è¨¼ JWTã¨ã¯ JWTã«ã¤ãã¦ã§ããã以ä¸ã®è¨äºãèªãã§ã¿ãã¨ã ãããåãããã¨æãã¾ãã techblog.yahoo.co.jp 以ä¸ã®ãã¼ã¸ã®ãããã¬ã¼ã®é¨åã§JW
Rustå ¥éã¡ã¢ã Rustã¯æååã表ãåã¨ã㦠&str 㨠String ããã ããããçµæ§ãããããã¦ãã©ãããã¨ãã«ã©ã£ã¡ã使ãã¹ããªã®ããããããããªã ç°å¢ OS: macOS High Sierra 10.13.3 Rust: rustc 1.26.0-nightly (c08480fce 2018-03-23) Rustã®æååå Rustã®æ¥æ¬èªDocument: æåå Rustã«ã¯ä¸»è¦ãªæåååãäºç¨®é¡ããã¾ãã&str 㨠Stringã§ãã ã¾ã &str ã«ã¤ãã¦èª¬æãã¾ãããã &str ã¯ãæååã¹ã©ã¤ã¹ãã¨å¼ã°ãã¾ãã æååã¹ã©ã¤ã¹ã¯åºå®ãµã¤ãºã§å¤æ´ä¸å¯è½ã§ããæååã¹ã©ã¤ã¹ã¯UTF-8ã®ãã¤ãã·ã¼ã±ã³ã¹ã¸ã®åç §ã§ãã Rustã«ã¯ &str ã ãã§ãªãã String ã¨ãããã¼ãã¢ãã±ã¼ããããæååãããã¾ãã ãã®æååã¯ä¼¸å¼µå¯è½ã§ãããã¾ã
String, &strãé£çµãã¦Stringãçæ: format! format!ãã¯ãã使ãã¨ãè¤æ°ã®Stringã&strãé£çµãã¦æ°ããªStringãçæã§ããã format in std - Rust 第ä¸å¼æ°ã®æååãªãã©ã«å ã®ãã¬ã¼ã¹ãã«ãã¼{}ã«ç¬¬äºå¼æ°ä»¥éã®å¤ãæ¿å ¥ããããæ°ããªStringãçæãããå ã®String, &strã¯ãã®ã¾ã¾ã let s_string = String::from("abc"); let s_str = "XYZ"; let s = format!("{}_123_{}", s_string, s_str); assert_eq!(s, "abc_123_XYZ"); assert_eq!(s_string, "abc"); assert_eq!(s_str, "XYZ");
ããã¯Rustãã®3 Advent Calendar 2019ã®åæ¥ã®è¨äºã§ãã sccache â MozillaãéçºããRust製ã®ã³ã³ãã¤ã«ãã£ãã·ã¥ Rustã¯ã³ã³ãã¤ã«è¨èªã§ããå人çã«ã¯Rustã®ã³ã³ãã¤ã«é度ã¯é ãã¯ãªãæ¹ã ã¨æã£ã¦ãã¾ãããä¾åãã¦ããã¯ã¬ã¼ããå¤ãã¨ãã«ãã«ãããæéãé·ããªãã¾ããç¹ã«éåæI/Oãè¡ãWebã¯ã©ã¤ã¢ã³ãï¼ãµã¼ãã¼ã®ã¯ã¬ã¼ãã使ã£ãã¨ãããCargoèªä½ãã©ã¤ãã©ãªã¨ãã¦ä½¿ãCargoãµãã³ãã³ãããã«ãããã¨ããªã©ã¯ãä¾åã¯ã¬ã¼ãã200åãããã«ãªããã¨ãããããã·ã³ã®æ§è½ã«ãã£ã¦ã¯ãã«ãã«ããªãã®æéãè¦ãã¾ãã ãã«ãæéãç縮ããããã«ã³ã³ãã¤ã«ãã£ãã·ã¥ã¨ãã種é¡ã®ã½ããã¦ã§ã¢ãããã¾ããããã¯ã³ã³ãã¤ã«ã«ãã£ã¦ä½ãããææç©ããã£ã¹ã¯ãªã©ã«ãã£ãã·ã¥ãã¦ãããåãæ¡ä»¶ã®ã³ã³ãã¤ã«è¦æ±ããã£ãã¨ãã«ã¯ããã£ãã·ã¥ãããã®ãè¿
ãããï½ï¼ããã£ããããï½ï¼ãããã¡ãããã®è¨äºèªãã§ãã¢ã¸ã¥ã¼ã«å®å ¨ã«ç解ãããã£ã¦è¨ã£ã¦ãªãã£ãã£ãã¼ï¼ ãã³ãããã¾ãããã¾ãå¿ãã¾ããã å¤ãã¦ã¯ãããªãã¨ãã ã«ã¼ããã¡ã¤ã« Rustã«ã¯ã«ã¼ããã¡ã¤ã«ã¨ããèãæ¹ãããã¾ãã以ä¸ã®ã©ã¡ãããrootã«ãªãã¾ãã src/main.rs src/lib.rs Cargo.tomlã§æ示çã«è¨å®ãã¦å¤æ´ãããã¨ãå¯è½ã§ãããã»ã¨ãã©ã®å ´åä¸è¨ã®ããã©ã«ãã使ç¨ããããã¨ã§ãããã ã«ã¼ããã¡ã¤ã«ããã®mod宣è¨ãå¿ è¦ ãããä¸çªéè¦ã§ããRustã§ã¯èªåãå®ç¾©ããã¢ã¸ã¥ã¼ã«ã¯ã«ã¼ããã¡ã¤ã«ããmodãã¼ã¯ã¼ãã使ã£ã¦å®£è¨ãå¿ è¦ã§ãã ãããªãã¨ãã®ãã¡ã¤ã«ã¯ç¡ããåç¶ã¨ãã¦æ±ãããã³ã³ãã¤ã«ããããã¾ããã
èªå·±ç´¹ä» åºç° å®ã¨ç³ãã¾ãã ãããªãPythonããã°ã©ãã§ãã æ å ±ã»ãã¥ãªãã£ã«èå³ãããç¾å¨åå¼·ä¸ã§ããCTFããã°ãã¦ã³ãã£ãªã©ã§è ã磨ãã¦ãã¾ãã主ã«ä½ã¬ã¤ã¤ã®æè¡ã好ãã§ããã£ã¡ã°ããç®ãè¡ããã¡ã§ãã Rustãåå¼·ãã¦ããããã§ãèªãã§å¦ã³ãæãåãããè¨é²ãã楽ããå¦ãã§ããããã¨æãã¾ãã ç°å¢ æ°ããè¨èªãå¦ã¶ã¨ãããã¨ã§ãæ®æ®µä½¿ããªãWindowsã¨Vimã¨ããæ°ããéçºç°å¢ã§è¡ã£ã¦ãã¾ãã OS: Windows10 Home 64bit 1903 CPU: Intel Core i5-3470 @ 3.20GHz Rust: 1.38.0 RAM: 8.00GB Editor: Vim 8.1.1 Terminal: PowerShell åå ååã¯ç§ã§ã¯ãªãä½è ããã©ãããæ´èµ°ãã¦ããããã§ããè¨æ¶ã«ãããã¾ããããã ãæ°ããå¦ãã loopãã¯ãã¼ã¸ã£ãª
ã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ãRustã§éçºãã¦ãããæ ªå¼ä¼ç¤¾estieãä»åéå¬ããããRustãä½ãããããªãâ¦ãã§ã¯ãå®ãµã¼ãã¹ã§æ´»ç¨ããã¦ããRustã«ã¤ãã¦ããã®æ´»ç¨æ¹æ³ã®äºä¾ãç´¹ä»ãã¾ãããestieã§ã¢ã«ãã¤ãã¨ãã¦Rustãç¨ããã¦ã§ãã¢ããªã®éçºã«åãçµãã§ããkenkooooæ°ããactix-webãã®æ´»ç¨ã«ã¤ãã¦çºè¡¨ãã¾ããã ã¢ã¸ã§ã³ãã®ç´¹ä» kenkooooæ°ï¼ã§ã¯åãkenkooooããactix-webã§å¿«é©Webã¢ããªçæ´»ãã¨ããã¿ã¤ãã«ã§çºè¡¨ãã¾ãããããããé¡ããã¾ãã ï¼ã¹ã©ã¤ãã示ãã¦ï¼ä»æ¥çºè¡¨ããããã¨ã¯ãactix-webã¨ããRustã®Webãã¬ã¼ã ã¯ã¼ã¯ããã©ãã ã使ãããããã¨ãããã¨ã§ãããããããããã¯ç«ã¡å ¥ã£ã話ãªã®ã§ãããactix-webã®ããã«ã¦ã§ã¢ã¨ããæ©è½ããã£ã¦ããããä»estieï¼æ ªå¼ä¼ç¤¾estieï¼ã§ãã£ãã使ã£ã¦ããã®ã§ã
What is actix? actixã¨ã¯ãRust製ã®Actorãã¬ã¼ã ã¯ã¼ã¯ã§ãã ï¼Java/Scalaã§ããã¨ãAkkaãã¡ã¸ã£ã¼ã§ããï¼ ã¢ã¯ã¿ã¼å士ãéåæã§ã¡ãã»ã¼ã¸ãããåãããå®å ¨ã«ä¸¦è¡å¦çãè¡ããã¨ãã§ãã¾ãã ãã®actixããã¼ã¹ã¨ãã¦Webéçºç¨æ©è½ã追å ããã®ãã 軽éã»é«éãªWebéçºãã¬ã¼ã ã¯ã¼ã¯ã§ããactix-webã§ãã actix-webã§éçºãããã¢ããªã¯ãå®è¡ãã¡ã¤ã«ã«HTTPãµã¼ãã¼ãå«ãã§ããããã ãã®ã¾ã¾ä½¿ããã¨ãã§ããããapacheãnginxã®å¾ãã«ç½®ããã¨ãã§ãã¾ãã Environment ä»å使ç¨ããåä½ç°å¢ã¯ä»¥ä¸ã®ã¨ããã§ãã OS : MacOS X 10.15.1 Rust : 1.42.0 â»actix-webã¯Rust 1.39以éã§åä½ãã¾ã Setup Rust & actix-web â»Rustã®ã¤ã³ã¹ãã¼ã«
ã¯ããã« ã¤ã³ãã©ã¯Dockerã¨Docker Composeã§ãã ããã¯ã¨ã³ãã¯actix-web(Rustã®ãã¬ã¼ã ã¯ã¼ã¯) ããã³ãã¨ã³ãã¯React(TypeScriptã®ãã¬ã¼ã ã¯ã¼ã¯) ãã¼ã¿ãã¼ã¹ã¯MySqlã§ãã ãªãã¤ã³ãã¼(todoãªã¹ã)ãç®æ¨ã«éçºãè¡ãã¾ãã ã¬ãã¸ããªã¼ã¯ãã¡ãã§ãã Rustã¯Cargo.tomlã«è¨è¿°ãã¦ããã±ã¼ã¸ããã¦ã³ãã¼ãããæ¹å¼ã§ãã ããã±ã¼ã¸ã®ææ°ãã¼ã¸ã§ã³ã¯ä»¥ä¸ã§ç¢ºèªããã¨è¯ãã§ãã ã¾ããRustã¯targetã¬ãã¸ããªã¼ãé常ã«éãã®ã§ãgitignoreã«å ¥ãã¦ããã¨ããã§ãã ããã¯ã¨ã³ãå´ ããã¯ã¨ã³ãå´ãå®è£ ãã¾ãã ç°å¢æ§ç¯
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}