{"id":14331,"date":"2017-09-25T13:44:55","date_gmt":"2017-09-25T04:44:55","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=14331"},"modified":"2018-11-14T16:33:43","modified_gmt":"2018-11-14T07:33:43","slug":"rust-%e3%82%92%e3%83%95%e3%83%ad%e3%83%b3%e3%83%88%e3%82%a8%e3%83%b3%e3%83%89%e9%96%8b%e7%99%ba%e3%81%a7%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2017\/09\/25\/rust-%e3%82%92%e3%83%95%e3%83%ad%e3%83%b3%e3%83%88%e3%82%a8%e3%83%b3%e3%83%89%e9%96%8b%e7%99%ba%e3%81%a7%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b\/","title":{"rendered":"Rust \u3092\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u958b\u767a\u3067\u4f7f\u3063\u3066\u307f\u308b"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u5e73\u5965\u3067\u3059\uff01<br \/>\n\u671d\u306e\u901a\u52e4\u6642\u306b TechCrunch \u3092\u8aad\u3080\u306e\u3067\u3059\u304c\u3001\u3053\u3093\u306a\u8a18\u4e8b\u3092\u898b\u3064\u3051\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/techcrunch.com\/2017\/07\/16\/death-to-c\/\">Death to C, ++<\/a><\/p>\n<p>\u696d\u52d9\u3067\u306f C \u3084 C++ \u3092\u4f7f\u3046\u3053\u3068\u304c\u591a\u304f\u3001\u78ba\u304b\u306b\u3053\u3053\u306b\u66f8\u304b\u308c\u3066\u3044\u308b\u3088\u3046\u306a\u3001\u30dd\u30a4\u30f3\u30bf\u30fc\u306e\u6271\u3044\u3092\u9593\u9055\u3063\u3066\u81f4\u547d\u7684\u306a\u30d0\u30b0\u3092\u57cb\u3081\u8fbc\u3080\u3053\u3068\u3082\u3042\u308a\u307e\u3057\u305f\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u3055\u3068\u79fb\u690d\u6027\u306e\u9ad8\u3055\u3001\u30e1\u30e2\u30ea\u30fc\u3092\u76f4\u63a5\u53c2\u7167\u3067\u304d\u305f\u308a\u3001\u5b9f\u884c\u901f\u5ea6\u3082\u901f\u304f\u3001\u4f55\u3067\u3082\u5b9f\u73fe\u3067\u304d\u308b\u30a4\u30e1\u30fc\u30b8\u304c\u3042\u308a\u3001\u597d\u304d\u306a\u8a00\u8a9e\u3067\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u6642\u4ee3\u306f\u5909\u308f\u308a\u3001\u65b0\u3057\u3044\u8a00\u8a9e Rust \u304c\u51fa\u3066\u304d\u3066\u3001C\/C++ \u3067\u66f8\u304b\u308c\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u304c\u7f6e\u304d\u63db\u3048\u3089\u308c\u3066\u3044\u308b\u3093\u3060\u306a\u3041\u3068\u3064\u304f\u3065\u304f\u6642\u306e\u6d41\u308c\u3092\u611f\u3058\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u304b\u3089 Rust \u306b\u8208\u5473\u3092\u6301\u3061\u59cb\u3081\u307e\u3057\u305f\u3002\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3082\u5145\u5b9f\u3057\u3066\u3044\u3066<a href=\"https:\/\/www.rust-lang.org\/ja-JP\/documentation.html\">\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u307e\u305f<a href=\"https:\/\/rust-lang-ja.github.io\/the-rust-programming-language-ja\/1.6\/book\/\">\u65e5\u672c\u8a9e\u30b5\u30a4\u30c8<\/a>\u3082\u3042\u308a\u3001\u5b66\u7fd2\u3059\u308b\u306b\u306f\u6700\u9069\u306a\u74b0\u5883\u304c\u63c3\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Rust \u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u4f7f\u3048\u306a\u3044\u304b\u306a<\/h2>\n<p>Rust \u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u4f7f\u3048\u306a\u3044\u304b\u306a\u3068\u3075\u3068\u601d\u3044\u307e\u3057\u305f\u3002\u78ba\u304b C \u3084 C++ \u306f <a href=\"https:\/\/kripken.github.io\/emscripten-site\/index.html\">emscripten<\/a>\u3067 Javascript \u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3067\u304d\u305f\u306e\u3067\u3001Rust \u3082\u3067\u304d\u308b\u306e\u3067\u306f\u3068\u3002<\/p>\n<p>Emscripten \u3068\u306f LLVM \u306e bitcode \u3092 JavaScript \u306b\u5909\u63db\u3059\u308b\u30b3\u30f3\u30d1\u30a4\u30e9\u3067\u3059\u3002<\/p>\n<p>\u8abf\u3079\u3066\u307f\u308b\u3068\u3001<a href=\"https:\/\/users.rust-lang.org\/t\/compiling-to-the-web-with-rust-and-emscripten\/7627\">Compiling to the web with Rust and emscripten<\/a> \u3068\u3044\u3046\u30da\u30fc\u30b8\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<h2>Emscripten \u304c\u51fa\u529b\u3067\u304d\u308b\u306e\u306f JavaScript \u3060\u3051\u3067\u306f\u306a\u3044<\/h2>\n<p>JavaScript \u8a95\u751f\u5f53\u521d\u306f\u3001\u4f7f\u3044\u65b9\u3068\u3057\u3066\u306f HTML \u306b\u98fe\u308a\u4ed8\u3051\u3092\u3059\u308b\u3088\u3046\u306a\u4f7f\u3044\u65b9\u3067\u3001\u624b\u8efd\u3055\u304c\u58f2\u308a\u3067\u3057\u305f\u3002\u3057\u304b\u3057\u73fe\u5728\u306e Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u8907\u96d1\u306a\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3084\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u51e6\u7406\u3001\u51e6\u7406\u901f\u5ea6\u306e\u9045\u3044\u30e2\u30d0\u30a4\u30eb\u306b\u3082\u5bfe\u5fdc\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u3001\u5b9f\u884c\u901f\u5ea6\u304c\u6c42\u3081\u3089\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u5404\u30d6\u30e9\u30a6\u30b6\u30d9\u30f3\u30c0\u30fc\u3082 JavaScript \u30a8\u30f3\u30b8\u30f3\u3092\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u3057\u3001JavaScript \u306f\u60f3\u50cf\u4ee5\u4e0a\u306b\u9ad8\u901f\u306b\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u306f\u3044\u307e\u3059\u304c\u3001\u66f4\u306a\u308b\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u6c42\u3081\u3089\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u767b\u5834\u3057\u3066\u304d\u305f\u306e\u304c asm.js \u3067\u3059\u3002asm.js \u306f JavaScript \u306e\u8a00\u8a9e\u4ed5\u69d8\u306b\u3042\u308b\u5236\u7d04\u3092\u3064\u3051\u3001\u578b\u3092\u660e\u78ba\u306b\u3057\u4e8b\u524d\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u6280\u8853\u306e\u3053\u3068\u3067\u3059\u3002\u3057\u304b\u3057 asm.js \u306b\u3082\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5927\u304d\u304f\u306a\u308b\u3001\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u6982\u5ff5\u304c\u306a\u3044\u306a\u3069\u306e\u6b20\u70b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u767b\u5834\u3057\u3066\u304d\u305f\u306e\u304c WebAssembly \u3067\u3059\u3002WebAssembly \u306f\u30d6\u30e9\u30a6\u30b6\u3067\u30d0\u30a4\u30ca\u30ea\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u6280\u8853\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5c0f\u3055\u304f\u306a\u308a\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5411\u4e0a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u6b20\u70b9\u3068\u3057\u3066\u306f\u307e\u3060 WebAssembly \u306f\u767a\u5c55\u9014\u4e2d\u3067\u3001DOM \u3084 WebAPI \u3001 GC \u306a\u3069\u304c\u4f7f\u3048\u307e\u305b\u3093\u3002\u3067\u3059\u306e\u3067\u73fe\u72b6\u3067\u306f\u91cd\u3044\u51e6\u7406\u306a\u3069\u3092 WebAssembly \u3067\u5b9f\u88c5\u3059\u308b\u3088\u3046\u306a\u4f7f\u3044\u65b9\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u5c06\u6765\u306f\u69d8\u3005\u306a<a href=\"https:\/\/github.com\/WebAssembly\/design\/blob\/master\/FutureFeatures.md\">\u6a5f\u80fd<\/a>\u304c\u8ffd\u52a0\u3055\u308c\u308b\u4e88\u5b9a\u306e\u3088\u3046\u3067\u3059\u3002\u8208\u5473\u306e\u3042\u308b\u65b9\u306f<a href=\"http:\/\/webassembly.org\"> \u516c\u5f0f\u30da\u30fc\u30b8 <\/a> \u306a\u3069\u3092\u898b\u3066\u3044\u305f\u3060\u3044\u305f\u3089\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>Emscripten \u306f asm.js\u3001WebAssembly \u306e\u4e21\u65b9\u3068\u3082\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u8a71\u306f\u9577\u304f\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u304b\u3089\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u3001\u5b9f\u969b\u306b\u52d5\u4f5c\u3055\u305b\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u74b0\u5883\u306f Linux \u3067\u3001\u4eca\u56de\u306f WebAssembly \u3067\u52d5\u4f5c\u3055\u305b\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u307e\u305a rustup \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>rustup \u306f rust \u306e\u958b\u767a\u74b0\u5883\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u4fbf\u5229\u30c4\u30fc\u30eb\u3067\u3059\u3002\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u7c21\u5358\u3067\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308c\u3070\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>curl https:\/\/sh.rustup.rs -sSf | sh<\/pre>\n<p>WebAssembly \u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3067\u304d\u308b\u3088\u3046\u306b\u30bf\u30fc\u30b2\u30c3\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>rustup target add wasm32-unknown-emscripten<\/pre>\n<h2>Emscripten \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u6b21\u306b Emscripten \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre>$ curl -O https:\/\/s3.amazonaws.com\/mozilla-games\/emscripten\/releases\/emsdk-portable.tar.gz\r\n$ tar -xzf emsdk-portable.tar.gz\r\n$ source emsdk-portable\/emsdk_env.sh\r\n$ emsdk update\r\n$ emsdk install sdk-incoming-64bit\r\n$ emsdk activate sdk-incoming-64bit\r\n<\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306b\u306f\u3060\u3044\u3076\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3092\u4f5c\u6210<\/h2>\n<p>\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u304a\u6c7a\u307e\u308a\u306e Hello World \u3067\uff01<br \/>\n\u307e\u305a hello \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>hello \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3089\u3001\u305d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4ee5\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fbmain.rs<\/p>\n<pre>fn main() {\r\n  println!(\"Hello, world!\");\r\n}\r\n<\/pre>\n<h2>\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5b9f\u884c<\/h2>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre>rustc --target=wasm32-unknown-emscripten main.rs -o hello.html<\/pre>\n<p>\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-24-2_No-00.png\" rel=\"facebox\" rel=\"attachment wp-att-14374\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-14374\" src=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-24-2_No-00.png\" alt=\"\" width=\"152\" height=\"72\" srcset=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-24-2_No-00.png 152w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-24-2_No-00-150x72.png 150w\" sizes=\"(max-width: 152px) 100vw, 152px\" \/><\/a><\/p>\n<h2>\u5b9f\u884c<\/h2>\n<p>\u4e0a\u8a18\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067 Web \u30b5\u30fc\u30d0\u30fc\u3092\u7acb\u3061\u4e0a\u3052\u308c\u3070\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f Python \u3067\u8d77\u52d5\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre>python -m SimpleHTTPServer\r\n<\/pre>\n<p>\u3067 Web \u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u304b\u3089 \u300chttp:\/\/localhost:8000\/hello.html\u300d\u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<br \/>\nWebAssembly \u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u3046\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-27-50_No-00.png\" rel=\"facebox\" rel=\"attachment wp-att-14376\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-14376\" src=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-27-50_No-00.png\" alt=\"\" width=\"1919\" height=\"506\" srcset=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-27-50_No-00.png 1919w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-27-50_No-00-300x79.png 300w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-27-50_No-00-768x203.png 768w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-5_21-27-50_No-00-1024x270.png 1024w\" sizes=\"(max-width: 1919px) 100vw, 1919px\" \/><\/a><\/p>\n<p>\u3068\u7c21\u5358\u306b\u74b0\u5883\u304c\u69cb\u7bc9\u3067\u304d\u3001\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>Rust \u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3066\u307f\u308b<\/h2>\n<p>\u5b9f\u884c\u3067\u304d\u308b\u74b0\u5883\u306e\u69cb\u7bc9\u304c\u3067\u304d\u305f\u306e\u3067\u3001\u4eca\u5ea6\u306f Rust \u306e\u95a2\u6570\u3092 JavaScript \u5074\u304b\u3089\u547c\u3073\u51fa\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u307e\u305a\u306f Rust \u306e\u30bd\u30fc\u30b9\u3067\u3042\u308b main.rs \u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<pre>fn main() {}\r\n\r\n#[no_mangle]\r\npub extern fn count(n: i32) -> i32 {\r\n    n + 1\r\n}\r\n<\/pre>\n<p>3\u884c\u76ee\u306e #[no_mangle] \u306f\u30b3\u30f3\u30d1\u30a4\u30e9\u304c\u540d\u524d\u3092\u5909\u66f4\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<br \/>\ncount \u306f\u4eca\u56de\u547c\u3073\u51fa\u3055\u308c\u308b\u95a2\u6570\u3067\u3059\u3002\u5f15\u6570\u3067\u6e21\u3055\u308c\u305f\u5024\u306b1\u52a0\u7b97\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002\u672c\u5f53\u306f\u91cd\u3044\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u307e\u305a\u306f\u8efd\u304f\u51e6\u7406\u3067\u3002\u307f\u306a\u3055\u307e\u306f\u3053\u3053\u306e\u51e6\u7406\u3092\u3001\u91cd\u3044\u51e6\u7406\u3067\u5b9f\u88c5\u3059\u308b\u3068 WebAssembly \u306e\u3059\u3054\u3055\u3092\u5b9f\u611f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u6b21\u306b HTML \u30d5\u30a1\u30a4\u30eb\u3092\u7528\u610f\u3057\u307e\u3059\u3002\u540d\u524d\u306f main.html \u3068\u3057\u307e\u3059\u3002<br \/>\nmain.html \u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>\r\n\r\n\r\n\r\n  \r\n  Count\r\n\r\n\r\n\r\n\r\n  <button class=\"mybutton\">Count<\/button>\r\n  <script>\r\n    \/\/ \u30b0\u30ed\u30fc\u30d0\u30eb\u3067\u5ba3\u8a00\u3059\u308b\u3002\r\n    \/\/ Emscripten\u3067\u4f7f\u7528\u3059\u308bModule\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3002\r\n    var Module = {};\r\n    var num = 0;\r\n    fetch('main.wasm')\r\n      .then((response) => response.arrayBuffer())\r\n      .then((buffer) => {\r\n        \/\/ Module.wasmBinary\u306bmain.wasm\u306e\u5185\u5bb9\u3092\u66f8\u304d\u8fbc\u3080\u3002\r\n        Module.wasmBinary = buffer;\r\n\r\n        \/\/ script\u30bf\u30b0\u3092\u8ffd\u52a0\u3057\u3066main.js\u3092\u5b9f\u884c\u3059\u308b\u3002\r\n        const scriptElem = document.createElement('script');\r\n        scriptElem.src = 'main.js';\r\n        document.body.appendChild(scriptElem);\r\n      });\r\n\r\n    document.querySelector('.mybutton').addEventListener('click', function () {\r\n      alert('check console');\r\n      var count = cwrap('count', 'number', ['number']);\r\n      num = count(num)\r\n      console.log(num);\r\n    });\r\n  <\/script>\r\n\r\n\r\n\r\n<\/pre>\n<p>\u8efd\u304f\u8aac\u660e\u3059\u308b\u3068\u300117\u884c\u76ee\u304b\u308927\u884c\u76ee\u307e\u3067\u3067\u3001wasm \u3092 Emscripten \u306e Module \u3067\u7ba1\u7406\u3059\u308b\u3088\u3046\u767b\u9332\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u3042\u3068\u306e24\u884c\u76ee\u304b\u308926\u884c\u76ee\u3067 script \u30bf\u30b0\u3092\u751f\u6210\u3057\u3001main.js \u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n11\u884c\u76ee\u306b\u30dc\u30bf\u30f3\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u306e\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3068\u304d\u306e\u51e6\u7406\u304c29\u884c\u76ee\u304b\u308933\u884c\u76ee\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001Rust \u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b count \u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002Emscripten \u306e Module \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e cwrap \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u547c\u3073\u51fa\u3057\u3092\u5b9f\u73fe\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30bd\u30fc\u30b9\u306e\u6e96\u5099\u304c\u3067\u304d\u305f\u306e\u3067\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002\u30b3\u30f3\u30d1\u30a4\u30eb\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre>rustc --target=wasm32-unknown-emscripten main.rs -o main.js -C link-args=\"-s EXPORTED_FUNCTIONS=['_count']\"\r\n<\/pre>\n<p>\u5148\u307b\u3069\u5b9f\u884c\u3057\u305f\u30b3\u30de\u30f3\u30c9\u3088\u308a\u9577\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u308c\u306f JavaScript \u5074\u3067\u547c\u3073\u51fa\u3055\u308c\u308b\u305f\u3081\u306e\u95a2\u6570\u540d\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002\u95a2\u6570\u540d\u306e\u524d\u306b\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u304c\u3064\u304f\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u4eca\u56de\u306f\u7c21\u7565\u5316\u306e\u305f\u3081\u3068\u8aac\u660e\u306e\u3057\u3084\u3059\u3055\u306e\u305f\u3081\u306b\u3053\u3053\u3067\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u30bd\u30fc\u30b9\u306b\u8a18\u8ff0\u3057\u305f\u308a\u3001 cargo \u3092\u5229\u7528\u3057\u3066\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u6e96\u5099\u304c\u3067\u304d\u305f\u306e\u3067\u3001\u305d\u308c\u3067\u306f\u3055\u3063\u305d\u304f\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<h2>Rust \u95a2\u6570\u547c\u3073\u51fa\u3057\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c<\/h2>\n<p>\u4ee5\u524d\u3068\u540c\u3058\u3088\u3046\u306b\u3001Web \u30b5\u30fc\u30d0\u30fc\u3092\u7acb\u3061\u4e0a\u3052\u307e\u3059\u3002<\/p>\n<pre>python -m SimpleHTTPServer\r\n<\/pre>\n<p>\u4eca\u56de\u306f\u30d5\u30a1\u30a4\u30eb\u304c\u5909\u308f\u3063\u3066\u3044\u308b\u306e\u3067\u300chttp:\/\/localhost:8000\/main.html\u300d\u3067\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3046\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-35-24_No-00-1.png\" rel=\"facebox\" rel=\"attachment wp-att-14388\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-14388\" src=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-35-24_No-00-1.png\" alt=\"\" width=\"891\" height=\"418\" srcset=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-35-24_No-00-1.png 891w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-35-24_No-00-1-300x141.png 300w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-35-24_No-00-1-768x360.png 768w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/a><\/p>\n<p>\u3053\u3053\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u30dc\u30bf\u30f3\u3092\u62bc\u4e0b\u3057\u307e\u3059\u3002\u305d\u308c\u304b\u3089 Console \u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-40-34_No-00.png\" rel=\"facebox\" rel=\"attachment wp-att-14390\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-14390\" src=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-40-34_No-00.png\" alt=\"\" width=\"815\" height=\"334\" srcset=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-40-34_No-00.png 815w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-40-34_No-00-300x123.png 300w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2017\/09\/SnapCrab_NoName_2017-9-6_21-40-34_No-00-768x315.png 768w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><\/a><\/p>\n<p>\u3061\u3083\u3093\u3068 Rust \u306e\u95a2\u6570\u304c\u547c\u3073\u51fa\u3055\u308c\u30ab\u30a6\u30f3\u30c8\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\uff01<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>Rust \u306f\u307e\u3060\u65b0\u3057\u3044\u8a00\u8a9e\u306a\u306e\u3067\u3001\u8cc7\u7523\u306a\u3069\u306f\u3042\u307e\u308a\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001C \u3084 C++ \u3067\u66f8\u304b\u308c\u305f\u30b3\u30fc\u30c9\u306f\u5927\u91cf\u306b\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u305d\u308c\u3092\u79fb\u690d\u3057\u518d\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u3001\u3044\u308d\u3044\u308d\u8a66\u3057\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u3002\u307e\u305f WebAssembly \u306f\u307e\u3060\u307e\u3060\u767a\u5c55\u9014\u4e2d\u306a\u306e\u3067\u3001\u3069\u3093\u306a\u6a5f\u80fd\u304c\u5b9f\u88c5\u3055\u308c\u308b\u306e\u304b\u697d\u3057\u307f\u3067\u3059\u3002\u307f\u306a\u3055\u307e\u3082\u8208\u5473\u3092\u6301\u305f\u308c\u305f\u3089\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01\u305d\u308c\u3067\u306f\u307e\u305f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u5e73\u5965\u3067\u3059\uff01<br \/>\n\u671d\u306e\u901a\u52e4\u6642\u306b TechCrunch \u3092\u8aad\u3080\u306e\u3067\u3059\u304c\u3001\u3053\u3093\u306a\u8a18\u4e8b\u3092\u898b\u3064\u3051\u307e\u3057\u305f\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2017\/09\/25\/rust-%e3%82%92%e3%83%95%e3%83%ad%e3%83%b3%e3%83%88%e3%82%a8%e3%83%b3%e3%83%89%e9%96%8b%e7%99%ba%e3%81%a7%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[270,271],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/14331"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=14331"}],"version-history":[{"count":63,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/14331\/revisions"}],"predecessor-version":[{"id":14501,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/14331\/revisions\/14501"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=14331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=14331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=14331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}