{"id":45331,"date":"2023-06-20T08:43:34","date_gmt":"2023-05-28T08:59:21","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/"},"modified":"2024-04-30T09:45:40","modified_gmt":"2024-04-30T01:45:40","slug":"45331-2","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/","title":{"rendered":""},"content":{"rendered":"<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (1)\u3000\u76ee\u7684<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (2)\u3000\u624b\u6bb5<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (3)\u3000FFI \u3067\u6570\u5024\u8a08\u7b97<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (4)\u3000Rutie \u3067\u6570\u5024\u8a08\u7b97\u2460<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (5)\u3000Rutie \u3067\u6570\u5024\u8a08\u7b97\u2461\u3000\u30d9\u30b8\u30a8<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (6)\u3000\u5f62\u614b\u7d20\u306e\u62bd\u51fa<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">Ruby\/Rust \u9023\u643a (7)\u3000\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6642\u30d3\u30eb\u30c9\u306e Rust \u62e1\u5f35 gem \u3092\u4f5c\u308b<\/ul>\n<h1>\u306f\u3058\u3081\u306b<\/h1>\n<p>\u524d\u56de\u306f FFI \u7d4c\u7531\u3067<\/p>\n<pre class=\"post-pre\"><code>\\sqrt{ x^2 + y^2 + z^2 }\r\n<\/code><\/pre>\n<p>\u3092\u8a08\u7b97\u3059\u308b Rust \u306e\u95a2\u6570\u3092 Ruby \u304b\u3089\u547c\u3093\u3067\u307f\u305f\u3002<br \/>\n\u610f\u5916\u3068\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3053\u3068\u304c\u5206\u304b\u3063\u305f\u306e\u306f\u53ce\u7a6b\u3060\u3063\u305f\u304c\uff0c\u809d\u5fc3\u306e\u901f\u5ea6\u306f\u3068\u3044\u3046\u3068\uff0cRuby \u3067<\/p>\n<pre class=\"post-pre\"><code><span class=\"no\">Math<\/span><span class=\"p\">.<\/span><span class=\"nf\">sqrt<\/span><span class=\"p\">(<\/span><span class=\"n\">x<\/span> <span class=\"o\">*<\/span> <span class=\"n\">x<\/span> <span class=\"o\">+<\/span> <span class=\"n\">y<\/span> <span class=\"o\">*<\/span> <span class=\"n\">y<\/span> <span class=\"o\">+<\/span> <span class=\"n\">z<\/span> <span class=\"o\">*<\/span> <span class=\"n\">z<\/span><span class=\"p\">)<\/span>\r\n<\/code><\/pre>\n<p>\u3092\u8a08\u7b97\u3059\u308b\u3088\u308a\u306f\u308b\u304b\u306b\u9045\u3044\uff0c\u3068\u3044\u3046\u6b8b\u5ff5\u306a\u3082\u306e\u3060\u3063\u305f\u3002<br \/>\n\u539f\u56e0\u306f\u3088\u304f\u5206\u304b\u3089\u306a\u3044\u304c\uff0cFFI \u3092\u7d4c\u7531\u3059\u308b\u30b3\u30b9\u30c8\u304c\u5927\u304d\u304b\u3063\u305f\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u63a8\u6e2c\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f FFI \u4ee5\u5916\u306e\u624b\u6bb5\u3067 Rust \u3068 Ruby \u3092\u7e4b\u3044\u3067\u307f\u305f\u3089\u3069\u3046\u3060\u308d\u3046\u3002<br \/>\n\u3053\u306e\u8a18\u4e8b\u3067\u306f Rutie \u3068\u3044\u3046\u3082\u306e\u3092\u4f7f\u3046\u3002<\/p>\n<p>Qiita \u306b\u306f Rutie \u306e\u8a18\u4e8b\u306f\u7121\u3044\u3088\u3046\u306a\u306e\u3067\uff0c\u3053\u308c\u304c\u6700\u521d\u306e\u8a18\u4e8b\u306b\u306a\u308b\u3068\u601d\u3046\u3002<\/p>\n<p>\u306a\u304a\uff0c<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">macOS 10.13.6\uff08High Sierra\uff09<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Rust 1.46.0<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">Ruby 2.7.1<\/ul>\n<p>\u3092\u4f7f\u7528\u3057\u305f\u3002<\/p>\n<h1>Rutie \u3068\u306f<\/h1>\n<p>\u516c\u5f0f\u30b5\u30a4\u30c8\uff1adanielpclark\/rutie: \u201cThe Tie Between Ruby and Rust.\u201d<\/p>\n<p>Rutie \u306f\u300c\u30eb\u30fc\u30c6\u30a3\u30fc\u300d\u306e\u3088\u3046\u306b\u8aad\u3080\u3089\u3057\u3044\u3002<\/p>\n<p>FFI \u304c\u8907\u6570\u306e\u8a00\u8a9e\u9593\u3092\u7d50\u3076\u6c4e\u7528\u306e\u4ed5\u7d44\u307f\u3067\u3042\u308b\u306e\u306b\u5bfe\u3057\uff0cRutie \u306f Ruby \u3068 Rust \u306e\u9593\u3060\u3051\u3092\u53d6\u308a\u6301\u3064\u3002<br \/>\n\u5927\u304d\u306a\u7279\u9577\u306f\uff0cRust \u3067 Ruby \u306e\u30af\u30e9\u30b9\uff0c\u30e2\u30b8\u30e5\u30fc\u30eb\uff0c\u30e1\u30bd\u30c3\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\uff0c\u3068\u3044\u3046\u3053\u3068\u3060\u3002<br \/>\nRuby \u306e String\uff0cArray\uff0cHash \u306b\u5bfe\u5fdc\u3059\u308b\u578b\u3082 Rust \u5074\u3067\u6301\u3063\u3066\u3044\u308b\u3002<br \/>\n\u307e\u305f\uff0cRust \u5074\u304b\u3089 Ruby \u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3053\u3068\u3082\u3067\u304d\u308b\u3089\u3057\u3044\u3002<\/p>\n<h1>\u984c\u6750<\/h1>\n<p>FFI \u306e\u3068\u304d\u3068\u540c\u3058\u304f<\/p>\n<pre class=\"post-pre\"><code>\\sqrt{ x^2 + y^2 + z^2 }\r\n<\/code><\/pre>\n<p>\u3092\u8a08\u7b97\u3059\u308b\u95a2\u6570\u3092 Rust \u3067\u8a18\u8ff0\u3057\uff0cRuby \u3067\u547c\u3093\u3067\u307f\u308b\u3002<\/p>\n<p>FFI \u306e\u3068\u304d\u306f\uff0cRust \u306e\u95a2\u6570\u3092 Ruby \u306e\u30e1\u30bd\u30c3\u30c9\u306b\u5272\u308a\u5f53\u3066\u308b\uff0c\u3068\u3044\u3046\u611f\u3058\u3060\u3063\u305f\u306e\u306b\u5bfe\u3057\uff0cRutie \u306e\u5834\u5408\u306f Rust \u3067\u76f4\u63a5 Ruby \u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8a18\u8ff0\u3059\u308b\uff0c\u3068\u3044\u3046\u611f\u3058\u306b\u306a\u308b\u3002<\/p>\n<h1>\u5b9f\u88c5\uff1aRust \u5074<\/h1>\n<p>FFI \u306e\u3068\u304d\u3068\u540c\u69d8\uff0cRust \u3092\u3042\u307e\u308a\u77e5\u3089\u306a\u3044\u4eba\u3067\u3082\u518d\u73fe\u3067\u304d\u308b\u3088\u3046\u306b\u66f8\u3044\u3066\u3044\u304f\u3002<br \/>\n\u305f\u3060\u3057\uff0cRust \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u6e08\u3093\u3067\u3044\u308b\u3068\u3059\u308b\u3002<\/p>\n<h2>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210<\/h2>\n<p>\u307e\u305a\u30bf\u30fc\u30df\u30ca\u30eb\u3067<\/p>\n<pre class=\"post-pre\"><code>cargo new my_rutie_math <span class=\"nt\">--lib<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3084\u3063\u3066\uff0cRust \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4e00\u3064\u4f5c\u308b\u3002<\/p>\n<p>my_rutie_math \u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3002\u3053\u308c\u3068\u540c\u540d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30fc\u304c\u51fa\u6765\uff0c\u305d\u3053\u306b\u521d\u671f\u30d5\u30a1\u30a4\u30eb\u4e00\u5f0f\u304c\u53ce\u307e\u308b\u3002<\/p>\n<p>&#8211;lib \u306f\u300c\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u30af\u30ec\u30fc\u30c8\u3092\u4f5c\u308b\u305e\u300d\u3068\u3044\u3046\u6307\u5b9a\u3002<\/p>\n<h2>Cargo.toml \u306e\u7de8\u96c6<\/h2>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30eb\u30fc\u30c8\u306e Cargo.toml \u306e\u672b\u5c3e\u304c [dependencies] \u3067\u7d42\u308f\u3063\u3066\u3044\u308b\u304c\uff0c\u3053\u308c\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nn\">[dependencies]<\/span>\r\n<span class=\"py\">rutie<\/span> <span class=\"p\">=<\/span> <span class=\"s\">\"0.7.0\"<\/span>\r\n\r\n<span class=\"nn\">[lib]<\/span>\r\n<span class=\"py\">crate-type<\/span> <span class=\"p\">=<\/span> <span class=\"nn\">[\"cdylib\"]<\/span>\r\n<\/code><\/pre>\n<p>\uff08\u8ffd\u8a18 2020-10-01\uff09rutie \u306e 2020-10-01 \u6642\u70b9\u306e\u6700\u65b0\u7248\u306f 0.8.1 \u306a\u306e\u3067\uff0c\u3044\u307e\u304b\u3089\u8a66\u3059\u4eba\u306f<\/p>\n<pre class=\"post-pre\"><code><span class=\"py\">rutie<\/span> <span class=\"p\">=<\/span> <span class=\"s\">\"0.8.1\"<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>[dependencies]<\/h3>\n<p>[dependencies] \u306e\u3068\u3053\u308d\u306f\uff0c\u4f9d\u5b58\u30af\u30ec\u30fc\u30c8\u306e\u6307\u5b9a\u3067\u3042\u308b\u3002Ruby \u3067\u8a00\u3048\u3070 Gemfile \u3067\u4f9d\u5b58 gem \u3092\u6307\u5b9a\u3059\u308b\u3088\u3046\u306a\u3082\u306e\u3002<br \/>\n\u3053\u3053\u3067\u306f\uff0crutie \u3068\u3044\u3046\u30af\u30ec\u30fc\u30c8\u3092\u4f7f\u3044\u307e\u3059\u3088\uff0c\u3068\u8a00\u3063\u3066\u3044\u308b\u3002<br \/>\n&#8220;0.7.0&#8221; \u306f rutie \u30af\u30ec\u30fc\u30c8\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u6307\u5b9a\u306a\u306e\u3060\u304c\uff0c\u300c\u30d0\u30fc\u30b8\u30e7\u30f3 0.7.0 \u306b\u3057\u308d\u300d\u3068\u3044\u3046\u610f\u5473\u3067\u306f\u306a\u304f\u300c\u30d0\u30fc\u30b8\u30e7\u30f3 0.7.0 \u4ee5\u4e0a\uff0c0.8.0 \u672a\u6e80\u300d\u3068\u3044\u3046\u6307\u5b9a\u306a\u306e\u3060\u3002<br \/>\n\u3064\u307e\u308a\uff0cRuby \u306e Gemfile \u3067\u8a00\u3048\u3070 &#8220;~&gt; 0.7.0&#8221; \u3068\u3044\u3046\u6307\u5b9a\u3068\u540c\u3058\u3002<\/p>\n<p>2020 \u5e74 9 \u6708 4 \u65e5\u6642\u70b9\u3067\u306e rutie \u30af\u30ec\u30fc\u30c8\u306e\u6700\u65b0\u30ea\u30ea\u30fc\u30b9\u306f\u30d0\u30fc\u30b8\u30e7\u30f3 0.8.0 \u306a\u306e\u3060\u304c\uff0c\u3069\u3046\u3044\u3046\u308f\u3051\u304b 0.8.0 \u3067\u306f\u3046\u307e\u304f\u3044\u304b\u306a\u304b\u3063\u305f\u306e\u30671\uff0c\u539f\u56e0\u7a76\u660e\u306f\u5f8c\u56de\u3057\u306b\u3057\u3066\uff0c\u4e00\u3064\u53e4\u3044 0.7.0 \u3067\u8a71\u3092\u9032\u3081\u308b\u3002<\/p>\n<p>\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u8aac\u660e\u306f 0.8.0 \u3092\u524d\u63d0\u306b\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u6ce8\u610f\u3055\u308c\u305f\u3044\u3002<\/p>\n<p>\uff08\u8ffd\u8a18 2020-10-01\uff09\u305d\u306e\u5f8c\uff0cmacOS \u3067 0.8.0 \u3092\u518d\u3073\u8a66\u3057\u305f\u3068\u3053\u308d\uff0c\u3068\u304f\u306b\u554f\u984c\u306f\u7121\u304b\u3063\u305f\u30020.8.1 \u3082\u5927\u4e08\u592b\u3060\u3063\u305f\u3002\u4f55\u304b\u74b0\u5883\u304c\u5909\u308f\u3063\u305f\u306e\u304b\u3082\u3002\u30d3\u30eb\u30c9\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u65b9\u306f\u6559\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>[lib]<\/h3>\n<p>\u6b21\u306e [lib] \u306e\u3068\u3053\u308d\u306e\u610f\u5473\u306f\u79c1\u306f\u3088\u304f\u5206\u304b\u3063\u3066\u3044\u306a\u3044\u3002<\/p>\n<p>crate-type \u306f\u6587\u5b57\u901a\u308a\u30af\u30ec\u30fc\u30c8\u306e\u30bf\u30a4\u30d7\u3092\u6307\u5b9a\u3059\u308b\u3082\u306e\u3002\u30d0\u30a4\u30ca\u30ea\u30fc\u30af\u30ec\u30fc\u30c8\u3068\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u30af\u30ec\u30fc\u30c8\u306e\u3046\u3061\uff0c\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u30af\u30ec\u30fc\u30c8\u3092\u4f5c\u308b\u308f\u3051\u3060\u304c\uff0c\u5b9f\u306f\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u30af\u30ec\u30fc\u30c8\u306b\u3082\u7a2e\u985e\u304c\u3042\u308b\u3088\u3046\u3060\u3002<br \/>\n\u4ee5\u4e0b\u306e\u8a18\u4e8b\u304c\u5f79\u306b\u7acb\u3064\u3002<\/p>\n<p>Rust \u306e crate_type \u3092\u307e\u3068\u3081\u3066\u307f\u305f &#8211; Qiita<\/p>\n<p>cdylib \u3068\u3044\u3046\u306e\u306f\uff0c\u4ed6\u8a00\u8a9e\uff08\u3064\u307e\u308a Rust \u4ee5\u5916\u306e\u8a00\u8a9e\uff09\u7528\u306e\u52d5\u7684\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u3092\u610f\u5473\u3059\u308b\u3089\u3057\u3044\u3002<br \/>\n\u3048\u3063\u3068\uff0cdy \u306f dynamic \u3067\uff0cc \u306f C \u8a00\u8a9e\u3092\u610f\u5473\u3059\u308b\u306e\u304b\u306a\uff1f<\/p>\n<h2>\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u30e1\u30bd\u30c3\u30c9\u306e\u8a18\u8ff0<\/h2>\n<p>\u3067\u306f\u672c\u4f53\u306e\u8a18\u8ff0\u3092\u3002<\/p>\n<p>Rutie \u3067\u306f Ruby \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3082\u30af\u30e9\u30b9\u3082\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\n\u4eca\u56de\u306f\u95a2\u6570\uff08\u7684\u30e1\u30bd\u30c3\u30c9\uff09\u3092\u4e00\u3064\u4f5c\u308a\u305f\u3044\u3060\u3051\u306a\u306e\u3067\uff0c\u30af\u30e9\u30b9\u3067\u306a\u304f\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u3057\u3088\u3046\u3002<br \/>\n\u30e2\u30b8\u30e5\u30fc\u30eb\u540d\u306f MyMath \u306b\u3059\u308b\u3002<br \/>\n\u30e1\u30bd\u30c3\u30c9\u540d\u306f hypot3 \u306b\u3057\uff0cMyMath \u306e\u7279\u7570\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u3002<br \/>\n\u65b9\u91dd\u306f\u56fa\u307e\u3063\u305f\u3002<\/p>\n<p>src\/lib.rs \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3002\u3082\u3068\u3082\u3068\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306e\u96db\u5f62\u304c\u66f8\u304b\u308c\u3066\u3044\u308b\u304c\uff0c\u3053\u308c\u306f\u524a\u9664\u3057\u3066\u3057\u307e\u3063\u3066\u69cb\u308f\u306a\u3044\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">#[macro_use]<\/span>\r\n<span class=\"k\">extern<\/span> <span class=\"n\">crate<\/span> <span class=\"n\">rutie<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"k\">use<\/span> <span class=\"nn\">rutie<\/span><span class=\"p\">::{<\/span><span class=\"n\">Object<\/span><span class=\"p\">,<\/span> <span class=\"n\">Module<\/span><span class=\"p\">,<\/span> <span class=\"n\">Float<\/span><span class=\"p\">};<\/span>\r\n\r\n<span class=\"nd\">module!<\/span><span class=\"p\">(<\/span><span class=\"n\">MyMath<\/span><span class=\"p\">);<\/span>\r\n\r\n<span class=\"nd\">methods!<\/span><span class=\"p\">(<\/span>\r\n    <span class=\"n\">MyMath<\/span><span class=\"p\">,<\/span>\r\n    <span class=\"mi\">_<\/span><span class=\"n\">rtself<\/span><span class=\"p\">,<\/span>\r\n\r\n    <span class=\"k\">fn<\/span> <span class=\"nf\">pub_hypot3<\/span><span class=\"p\">(<\/span><span class=\"n\">x<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">,<\/span> <span class=\"n\">y<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">,<\/span> <span class=\"n\">z<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">)<\/span> <span class=\"k\">-&gt;<\/span> <span class=\"n\">Float<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"k\">let<\/span> <span class=\"n\">x<\/span> <span class=\"o\">=<\/span> <span class=\"n\">x<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n        <span class=\"k\">let<\/span> <span class=\"n\">y<\/span> <span class=\"o\">=<\/span> <span class=\"n\">y<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n        <span class=\"k\">let<\/span> <span class=\"n\">z<\/span> <span class=\"o\">=<\/span> <span class=\"n\">z<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n        <span class=\"nn\">Float<\/span><span class=\"p\">::<\/span><span class=\"nf\">new<\/span><span class=\"p\">((<\/span><span class=\"n\">x<\/span> <span class=\"o\">*<\/span> <span class=\"n\">x<\/span> <span class=\"o\">+<\/span> <span class=\"n\">y<\/span> <span class=\"o\">*<\/span> <span class=\"n\">y<\/span> <span class=\"o\">+<\/span> <span class=\"n\">z<\/span> <span class=\"o\">*<\/span> <span class=\"n\">z<\/span><span class=\"p\">)<\/span><span class=\"nf\">.sqrt<\/span><span class=\"p\">())<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">);<\/span>\r\n\r\n<span class=\"nd\">#[allow(non_snake_case)]<\/span>\r\n<span class=\"nd\">#[no_mangle]<\/span>\r\n<span class=\"k\">pub<\/span> <span class=\"k\">extern<\/span> <span class=\"s\">\"C\"<\/span> <span class=\"k\">fn<\/span> <span class=\"nf\">Init_MyMath<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"nn\">Module<\/span><span class=\"p\">::<\/span><span class=\"nf\">new<\/span><span class=\"p\">(<\/span><span class=\"s\">\"MyMath\"<\/span><span class=\"p\">)<\/span><span class=\"nf\">.define<\/span><span class=\"p\">(|<\/span><span class=\"n\">module<\/span><span class=\"p\">|<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"n\">module<\/span><span class=\"nf\">.def_self<\/span><span class=\"p\">(<\/span><span class=\"s\">\"hypot3\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">pub_hypot3<\/span><span class=\"p\">)<\/span>\r\n    <span class=\"p\">});<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>FFI \u7248\u3068\u6bd4\u3079\u308b\u3068\u8a18\u8ff0\u91cf\u304c\u3084\u3084\u591a\u3044\u3002<\/p>\n<h3>\u30de\u30af\u30ed<\/h3>\n<p>\u307e\u305a\uff0cmodule! \u3068 methods! \u306b\u6ce8\u76ee\u3002<br \/>\n\u3053\u308c\u3089\u306f rutie \u30af\u30ec\u30fc\u30c8\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30de\u30af\u30ed\u3067\uff0cRuby \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3059\u308b\u3082\u306e\u3089\u3057\u3044\u3002<\/p>\n<p>\u3053\u308c\u3089\u306e\u30de\u30af\u30ed\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\uff0c\u5192\u982d\u306b<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">#[macro_use]<\/span>\r\n<span class=\"k\">extern<\/span> <span class=\"n\">crate<\/span> <span class=\"n\">rutie<\/span><span class=\"p\">;<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3044\u3046\u8a18\u8ff0\u304c\u5fc5\u8981\u306b\u306a\u308b\uff08\u77e5\u3089\u3093\u3051\u3069\uff09\u3002<\/p>\n<h3>Object, Module, Float<\/h3>\n<p>Rutie \u3067\u306f\uff0cRuby \u306e Object\uff0cModule\uff0cClass\uff0cArray\uff0cFloat\uff0cHash\uff0cSymbol \u3068\u3044\u3063\u305f\u30af\u30e9\u30b9\u306b\u5bfe\u5fdc\u3059\u308b Rust \u306e\u578b\u304c\u540c\u3058\u540d\u524d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3060\u3002<br \/>\n\u305f\u3060\u3057\uff0cRuby \u306e String \u306b\u3064\u3044\u3066\u306f\u540c\u540d\u3067\u306f\u306a\u304f RString \u3068\u3044\u3046\u540d\u524d\u306b\u306a\u3063\u3066\u3044\u308b\u3002Rust \u306e String \u3068\u304b\u3076\u3089\u306a\u3044\u3088\u3046\u306b R \u3092\u4ed8\u3051\u305f\u306e\u3060\u308d\u3046\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3053\u308c\u3089\u306e\u3046\u3061\uff0cObject, Module, Float \u306e\u4e09\u3064\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\uff0c<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">use<\/span> <span class=\"nn\">rutie<\/span><span class=\"p\">::{<\/span><span class=\"n\">Object<\/span><span class=\"p\">,<\/span> <span class=\"n\">Module<\/span><span class=\"p\">,<\/span> <span class=\"n\">Float<\/span><span class=\"p\">};<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u66f8\u3044\u3066\u304a\u304f\u3002<\/p>\n<h3>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5b9a\u7fa9<\/h3>\n<p>MyMath \u3068\u3044\u3046 Ruby \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u308b\u306b\u306f<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">module!<\/span><span class=\"p\">(<\/span><span class=\"n\">MyMath<\/span><span class=\"p\">);<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u66f8\u304f\u3002<br \/>\n\u305f\u3076\u3093\u5b9f\u969b\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u51fa\u6765\u308b\u306e\u306f\u3053\u306e\u7b87\u6240\u3067\u306f\u306a\u304f\uff0c\u3042\u3068\u306e\u307b\u3046\u306b\u51fa\u3066\u304f\u308b Module::new(&#8220;MyMath&#8221;) \u3092\u5b9f\u884c\u3057\u305f\u3068\u304d\u306a\u3093\u3060\u308d\u3046\u3002<\/p>\n<h3>\u30e1\u30bd\u30c3\u30c9\u306e\u5b9a\u7fa9<\/h3>\n<p>\u30e1\u30bd\u30c3\u30c9\u306e\u5b9a\u7fa9\u306f methods! \u30de\u30af\u30ed\u306b\u4e09\u3064\u306e\u5f15\u6570\u3092\u4e0e\u3048\u3066\u3044\u308b\u3002<br \/>\n\u7b2c\u4e00\u5f15\u6570\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u540d MyMath\u3002<br \/>\n\u7b2c\u4e8c\u5f15\u6570\u306e _rtself \u306f\u3055\u3063\u3071\u308a\u5206\u304b\u3089\u306a\u3044\u3002<\/p>\n<p>\u7b2c\u4e09\u5f15\u6570\u306b\u95a2\u6570\u306e\u5b9a\u7fa9\u3092\u4e0e\u3048\u3066\u3044\u308b\u3002<br \/>\n\u629c\u304d\u51fa\u3057\u3066\u307f\u3088\u3046\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">fn<\/span> <span class=\"nf\">pub_hypot3<\/span><span class=\"p\">(<\/span><span class=\"n\">x<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">,<\/span> <span class=\"n\">y<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">,<\/span> <span class=\"n\">z<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">)<\/span> <span class=\"k\">-&gt;<\/span> <span class=\"n\">Float<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"k\">let<\/span> <span class=\"n\">x<\/span> <span class=\"o\">=<\/span> <span class=\"n\">x<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n    <span class=\"k\">let<\/span> <span class=\"n\">y<\/span> <span class=\"o\">=<\/span> <span class=\"n\">y<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n    <span class=\"k\">let<\/span> <span class=\"n\">z<\/span> <span class=\"o\">=<\/span> <span class=\"n\">z<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n    <span class=\"nn\">Float<\/span><span class=\"p\">::<\/span><span class=\"nf\">new<\/span><span class=\"p\">((<\/span><span class=\"n\">x<\/span> <span class=\"o\">*<\/span> <span class=\"n\">x<\/span> <span class=\"o\">+<\/span> <span class=\"n\">y<\/span> <span class=\"o\">*<\/span> <span class=\"n\">y<\/span> <span class=\"o\">+<\/span> <span class=\"n\">z<\/span> <span class=\"o\">*<\/span> <span class=\"n\">z<\/span><span class=\"p\">)<\/span><span class=\"nf\">.sqrt<\/span><span class=\"p\">())<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u307e\u305a\u95a2\u6570\u540d\u306a\u306e\u3060\u304c\uff0cpub_ \u3092\u982d\u306b\u4ed8\u3051\u3066\u3044\u308b\u306e\u306f\uff0cRutie \u306e\u30b5\u30a4\u30c8\u306b\u8f09\u3063\u3066\u3044\u308b\u30b3\u30fc\u30c9\u4f8b\u3067\uff0c\u300c\u95a2\u6570\u540d\u304c\u4ed6\u3068\u304b\u3076\u3089\u306a\u3044\u3088\u3046 pub_ \u3092\u4ed8\u3051\u305f\u300d\u3068\u3057\u3066\u3044\u308b\u306e\u306b\u5023\u3063\u305f\u3082\u306e\u3067\uff0c\u304b\u3076\u3089\u306a\u3044\u3053\u3068\u304c\u306f\u3063\u304d\u308a\u3057\u3066\u3044\u308c\u3070\u4ed8\u3051\u306a\u304f\u3066\u3088\u3044\u3002<br \/>\n\u306a\u304a\uff0cpub_hypot3 \u304c Ruby \u5074\u3067\u306f hypot3 \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u540d\u306b\u306a\u308b\u3088\u3046\u306b\u3059\u308b\u306e\u3067\uff0c\u5b89\u5fc3\u3055\u308c\u305f\u3044\u3002<\/p>\n<p>\u3055\u3066\uff0c\u5f15\u6570\uff0c\u8fd4\u308a\u5024\u306f\u3068\u3082\u306b f64 \u3067\u306a\u304f Float \u578b\u306b\u306a\u3063\u3066\u3044\u308b\u3002<br \/>\nFloat \u306f\u3053\u3053\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3060\uff1a<br \/>\nhttps:\/\/github.com\/danielpclark\/rutie\/blob\/v0.7.0\/src\/class\/float.rs<\/p>\n<p>\u3053\u3053\u306b\u66f8\u304b\u308c\u305f\u30b3\u30e1\u30f3\u30c8\u304c\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u3057\u3066\u4e0b\u8a18\u3067\u898b\u3089\u308c\u308b\uff1a<br \/>\nhttps:\/\/docs.rs\/rutie\/0.7.0\/rutie\/struct.Float.html<\/p>\n<p>\u3053\u3053\u3067\u5927\u304d\u306a\u7591\u554f\u304c\u6d8c\u3044\u305f\u3002\u5f15\u6570\u304b\u3089 f64 \u306b\u5909\u63db\u3059\u308b\u3068\u3053\u308d\u3067<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">x<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">()<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3060\u3002<br \/>\n\u3055\u304d\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3088\u308c\u3070\uff0cFloat \u306f to_f64() \u3067 f64 \u306b\u5909\u63db\u3067\u304d\u308b\u306f\u305a\u3002<br \/>\n\u306a\u305c\u306b unwrap() \u3092\u304b\u307e\u3057\u3066\u3044\u308b\u306e\u304b\uff1f<br \/>\n\u3069\u3046\u3082\uff0c\u3053\u306e x \u306e\u578b\u306f<\/p>\n<pre class=\"post-pre\"><code>std::result::Result&lt;rutie::Float, rutie::AnyException&gt;\r\n<\/code><\/pre>\n<p>\u3067\u3042\u308b\u3089\u3057\u3044\u3002\u304a\u305d\u3089\u304f\uff0cRuby \u304b\u3089\u5024\u3092\u3082\u3089\u3046\u3068\u304d\u306b\uff0c\u5909\u306a\u3082\u306e\u3092\u6e21\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067 Result \u306b\u306a\u3063\u3066\u3044\u308b\u3093\u3060\u308d\u3046\u306a\u3002\u3060\u304b\u3089 unwrap() \u3067 Float \u578b\u306e\u5024\u3092\u53d6\u308a\u51fa\u3059\u306e\u3060\u308d\u3046\u3002<br \/>\n\u3093\u304c\uff0c\u3057\u304b\u3057\uff01\u3000\u95a2\u6570\u306e\u578b\u306f<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">fn<\/span> <span class=\"nf\">pub_hypot3<\/span><span class=\"p\">(<\/span><span class=\"n\">x<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">,<\/span> <span class=\"n\">y<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">,<\/span> <span class=\"n\">z<\/span><span class=\"p\">:<\/span> <span class=\"n\">Float<\/span><span class=\"p\">)<\/span> <span class=\"k\">-&gt;<\/span> <span class=\"n\">Float<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u306a\u3063\u3066\u3044\u305f\u3067\u306f\u306a\u3044\u304b\u3002Float \u3060\u3088\uff0cx \u306f\u3002<br \/>\n\u3041\u3093\u301c\uff1f<\/p>\n<p>\u8abf\u3079\u3066\u3082\u79c1\u306e\u80fd\u529b\u3067\u306f\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u3002<br \/>\n\u305f\u3060\uff0c\u3053\u306e\u7b87\u6240\u306f methods! \u30de\u30af\u30ed\u306e\u5f15\u6570\u3067\u3042\u308b\uff0c\u3068\u3044\u3046\u3068\u3053\u308d\u304c\u30dd\u30a4\u30f3\u30c8\u304b\u3082\u3057\u308c\u306a\u3044\u3068\u601d\u3063\u305f\u3002<br \/>\n\u305d\u3046\uff0c\u3053\u306e\u95a2\u6570\u5b9a\u7fa9\u3089\u3057\u304d\u3082\u306e\u306f\u30de\u30af\u30ed\u306b\u6e21\u3055\u308c\u308b\u4f55\u304b\u306a\u306e\u3060\u3002Rust \u306e\u95a2\u6570\u305d\u306e\u3082\u306e\u3067\u306f\u306a\u3044\u3002<\/p>\n<p>\u3053\u306e\u554f\u984c\u306f\u8107\u306b\u7f6e\u3044\u3066\u5148\u306b\u9032\u3082\u3046\u3002<br \/>\n\u95a2\u6570\u672c\u4f53\u3067\u306f<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">let<\/span> <span class=\"n\">x<\/span> <span class=\"o\">=<\/span> <span class=\"n\">x<\/span><span class=\"nf\">.unwrap<\/span><span class=\"p\">()<\/span><span class=\"nf\">.to_f64<\/span><span class=\"p\">();<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3057\u3066\u3044\u308b\u3002\u5f15\u6570\u306b x \u304c\u3042\u308b\u306e\u306b\u540c\u540d\u306e x \u3092\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u306e\u306f\uff0c\u3044\u308f\u3086\u308b\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u3068\u3044\u3046\u3084\u3064\u3002\u5143\u306e x \u306f\u3082\u3046\u3053\u3053\u4ee5\u964d\u3067\u306f\u8981\u3089\u306a\u3044\u306e\u3067\uff0c\u540c\u3058\u540d\u524d\u306e\u5909\u6570\u3092\u4f7f\u3046\u306d\uff0c\u3063\u3066\u3053\u3068\u3002<\/p>\n<p>\u6700\u5f8c\u306e<\/p>\n<pre class=\"post-pre\"><code><span class=\"nn\">Float<\/span><span class=\"p\">::<\/span><span class=\"nf\">new<\/span><span class=\"p\">((<\/span><span class=\"n\">x<\/span> <span class=\"o\">*<\/span> <span class=\"n\">x<\/span> <span class=\"o\">+<\/span> <span class=\"n\">y<\/span> <span class=\"o\">*<\/span> <span class=\"n\">y<\/span> <span class=\"o\">+<\/span> <span class=\"n\">z<\/span> <span class=\"o\">*<\/span> <span class=\"n\">z<\/span><span class=\"p\">)<\/span><span class=\"nf\">.sqrt<\/span><span class=\"p\">())<\/span>\r\n<\/code><\/pre>\n<p>\u306f\uff0c\u8a08\u7b97\u3055\u308c\u305f f64 \u306e\u5024\u3092\u5143\u306b\uff0cRuby \u5074\u306b\u8fd4\u3059 Float \u578b\u306e\u5024\u3092\u751f\u6210\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3002<\/p>\n<h3>\u521d\u671f\u5316\u95a2\u6570\u306e\u5b9a\u7fa9<\/h3>\n<p>\u300c\u521d\u671f\u5316\u95a2\u6570\u300d\u3068\u3044\u3046\u547c\u3073\u65b9\u306f\u79c1\u304c\u52dd\u624b\u306b\u8003\u3048\u305f\u3082\u306e\u3067\uff0c\u9069\u5207\u3067\u306a\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u3068\u3082\u304b\u304f\uff0cRuby \u5074\u304b\u3089\u547c\u3073\u51fa\u3059\u95a2\u6570\u3092\u4e00\u3064\u5b9a\u7fa9\u3059\u308b\u3002\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\uff0cRust \u3067\u5b9a\u7fa9\u3057\u305f Ruby \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3084\u30e1\u30bd\u30c3\u30c9\u304c Ruby \u5074\u3067\u5b9f\u969b\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3060\u308d\u3046\u3068\u601d\u3046\u3002<\/p>\n<p>\u4ee5\u4e0b\u306b\u629c\u7c8b\u3059\u308b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">#[allow(non_snake_case)]<\/span>\r\n<span class=\"nd\">#[no_mangle]<\/span>\r\n<span class=\"k\">pub<\/span> <span class=\"k\">extern<\/span> <span class=\"s\">\"C\"<\/span> <span class=\"k\">fn<\/span> <span class=\"nf\">Init_mymath<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"nn\">Module<\/span><span class=\"p\">::<\/span><span class=\"nf\">new<\/span><span class=\"p\">(<\/span><span class=\"s\">\"MyMath\"<\/span><span class=\"p\">)<\/span><span class=\"nf\">.define<\/span><span class=\"p\">(|<\/span><span class=\"n\">module<\/span><span class=\"p\">|<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"n\">module<\/span><span class=\"nf\">.def_self<\/span><span class=\"p\">(<\/span><span class=\"s\">\"hypot3\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">pub_hypot3<\/span><span class=\"p\">)<\/span>\r\n    <span class=\"p\">});<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u95a2\u6570\u540d\u306e\u547d\u540d\u898f\u5247\u304c\u5206\u304b\u3089\u306a\u3044\u304c\uff0c\u30b3\u30fc\u30c9\u4f8b\u306b\u5f93\u3063\u3066\uff0cInit_XXXX \u306e\u5f62\u5f0f\u306b\u3057\u305f\u3002<br \/>\n\u5192\u982d\u306b #[allow(non_snake_case)] \u3068\u3042\u308b\u306e\u306f\uff0c\u300c\u30b9\u30cd\u30fc\u30af\u30b1\u30fc\u30b9\u306b\u3057\u306a\u304b\u3063\u305f\u306e\u306f\u610f\u56f3\u7684\u306a\u3093\u3060\u304b\u3089\u6587\u53e5\u8a00\u3046\u306a\u3088\u300d\u3068\u30b3\u30f3\u30d1\u30a4\u30e9\u30fc\u306b\u91d8\u3092\u523a\u3057\u3066\u3044\u308b\u306e\u3060\u308d\u3046\u3002<\/p>\n<p>#[no_mangle] \u306f\uff0c\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u304c\u5916\u90e8\u306b\u898b\u305b\u308b\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u304d\u306b\u4ed8\u3051\u308b\u304a\u306a\u3058\u307f\u306e\u546a\u6587\u3067\uff0c\u3053\u308c\u3092\u3064\u3051\u306a\u3044\u3068\u95a2\u6570\u540d\u304c\u305d\u306e\u540d\u3067\u53c2\u7167\u3067\u304d\u306a\u304f\u306a\u308b\u3068\u3044\u3046\u3053\u3068\u3089\u3057\u3044\u3002<\/p>\n<p>\u95a2\u6570\u306e\u4e2d\u8eab\u306f\uff0c\u307e\u305a Module::new(&#8220;MyMath&#8221;) \u3067\u30e2\u30b8\u30e5\u30fc\u30eb MyMath \u3092\u4f5c\u6210\u3057\uff0c\u305d\u308c\u306b\u5bfe\u3057\u3066 def_self \u3067\u30e1\u30bd\u30c3\u30c9\u3092\u751f\u3084\u3057\u3066\u3044\u308b\u3088\u3046\u3060\u3002<br \/>\ndefine \u306e\u5f15\u6570\u306f<\/p>\n<pre class=\"post-pre\"><code><span class=\"p\">|<\/span><span class=\"n\">module<\/span><span class=\"p\">|<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"n\">module<\/span><span class=\"nf\">.def_self<\/span><span class=\"p\">(<\/span><span class=\"s\">\"hypot3\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">pub_hypot3<\/span><span class=\"p\">)<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3044\u3046\u5f62\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u3053\u308c\u306f\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u3068\u547c\u3070\u308c\u308b\u3082\u306e\u3002<br \/>\nRuby \u306e\u30d6\u30ed\u30c3\u30af\u3068\u3088\u304f\u4f3c\u305f\u69cb\u6587\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u304c\u9762\u767d\u3044\u3002Ruby \u306e\u30d6\u30ed\u30c3\u30af\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u5f53\u305f\u308b\u90e8\u5206\u304c { } \u306e\u5916\u306b\u51fa\u3066\u3044\u308b\u70b9\u304c\u9055\u3063\u3066\u3044\u308b\u3051\u308c\u3069\u3082\u3002<br \/>\nRuby \u306e\u30d6\u30ed\u30c3\u30af\u306f\u5024\u3067\u306f\u306a\u3044\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u306f\u306a\u3044\uff09\u304c\uff0cRust \u306e\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u306f\u5024\u3067\u3042\u308a\uff0c\u95a2\u6570\u306e\u5f15\u6570\u306b\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>module.def_self(&#8220;hypot3&#8221;, pub_hypot3) \u306f\uff0c\u5148\u306b\u5b9a\u7fa9\u3057\u305f pub_hypot3 \u3092\uff0chypot3 \u3068\u3044\u3046\u540d\u524d\u306e\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066\u30e2\u30b8\u30e5\u30fc\u30eb MyMath \u306b\u751f\u3084\u3059\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3088\u3046\u3060\u3002<\/p>\n<p>\u3053\u308c\u3067 Rust \u5074\u306e\u5b9f\u88c5\u306f\u30aa\u30b7\u30de\u30a4\u3002<br \/>\n\u3044\u304f\u3064\u304b\u7406\u89e3\u3067\u304d\u306a\u3044\u70b9\u304c\u3042\u3063\u305f\u3057\uff0c\u3061\u3087\u3063\u3068\u3084\u3084\u3053\u3057\u3044\u611f\u3058\u3082\u3059\u308b\u3002<br \/>\n\u3057\u304b\u3057\uff0c\u3053\u306e\u7a0b\u5ea6\u306e\u8907\u96d1\u3055\u3067\uff0cRuby \u306e\u30af\u30e9\u30b9\u3084\u30e2\u30b8\u30e5\u30fc\u30eb\u3084\u30e1\u30bd\u30c3\u30c9\u304c\u5b9a\u7fa9\u3067\u304d\u308b\u306a\u3089\uff0c\u3044\u3044\u3093\u3067\u306f\u306a\u3044\u304b\uff1f<\/p>\n<h2>\u30b3\u30f3\u30d1\u30a4\u30eb<\/h2>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30fc\u3067<\/p>\n<pre class=\"post-pre\"><code>cargo build <span class=\"nt\">--release<\/span>\r\n<\/code><\/pre>\n<p>\u3068\u3084\u308b\u3002<br \/>\n\u3059\u308b\u3068\uff0c\u6210\u679c\u7269\u304c target\/release\/libmy_rutie_math.dylib \u3068\u3044\u3046\u30d1\u30b9\u306b\u51fa\u6765\u308b\u3002<br \/>\n\u305f\u3060\u3057\uff0c\u62e1\u5f35\u5b50\u306f\u30bf\u30fc\u30b2\u30c3\u30c8\u306b\u3088\u3063\u3066\u7570\u306a\u308b\u306f\u305a\u3002Windows \u3060\u3068 .dll \u306b\u306a\u308b\u306e\u304b\u306a\u3002<\/p>\n<p>\uff08\u8ffd\u8a18\uff09<br \/>\n\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u3068\u304d\uff0c<\/p>\n<pre class=\"post-pre\"><code>warning: `extern` fn uses type `MyMath`, which is not FFI-safe\r\n --&gt; src\/lib.rs:9:5\r\n  |\r\n9 |     MyMath,\r\n  |     ^^^^^^ not FFI-safe\r\n<\/code><\/pre>\n<p>\u3068\u3044\u3046\u8b66\u544a\u304c\u51fa\u308b\u3002<br \/>\n\uff08Ruby \u3084 Rust \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u8a18\u4e8b\u306e\u5192\u982d\u306b\u66f8\u3044\u3066\u304a\u3044\u305f\uff09<\/p>\n<p>MyMath \u3068\u3044\u3046\u540d\u524d\u304c\u300cFFI-safe \u3067\u306a\u3044\u300d\u3068\u8a00\u3063\u3066\u3044\u308b\u3088\u3046\u3060\u3002<br \/>\n\u3069\u3046\u3044\u3046\u3053\u3068\u304b\u5168\u304f\u5206\u304b\u3089\u306a\u3044\u304c\uff0c\u30a8\u30e9\u30fc\u3067\u306a\u304f\u8b66\u544a\u306a\u306e\u3067\uff0c\u3055\u3057\u3042\u305f\u308a\u7121\u8996\u3059\u308b\u3053\u3068\u306b\u3059\u308b\u3002<\/p>\n<p>\uff08\u8ffd\u8a18 2020-10-01\uff09not FFI-safe \u3068\u3044\u3046\u8b66\u544a\u306f\uff0cRust 1.46 \u3067\u51fa\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3082\u306e\u3002Rutie 0.8.1 \u3067\u89e3\u6d88\u3055\u308c\u305f\u3002<br \/>\nhttps:\/\/github.com\/danielpclark\/rutie\/issues\/128<\/p>\n<h1>\u5b9f\u88c5\uff1aRuby \u5074<\/h1>\n<p>Ruby \u5074\u3067\u306f\uff0crutie \u3068\u3044\u3046 gem \u3092\u4f7f\u3046\u3002Rust \u3067\u4f7f\u3046\u30af\u30ec\u30fc\u30c8\u3068\u540c\u3058\u540d\u524d\u3002\u5206\u304b\u308a\u3084\u3059\u3044\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306f\uff0cRust \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30fc\u306b\u5b58\u5728\u3059\u308b\u3068\u4eee\u5b9a\u3057\u3066\u66f8\u3044\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">gem<\/span> <span class=\"s2\">\"rutie\"<\/span><span class=\"p\">,<\/span> <span class=\"s2\">\"~&gt; 0.0.4\"<\/span>\r\n<span class=\"nb\">require<\/span> <span class=\"s2\">\"rutie\"<\/span>\r\n\r\n<span class=\"no\">Rutie<\/span><span class=\"p\">.<\/span><span class=\"nf\">new<\/span><span class=\"p\">(<\/span><span class=\"ss\">:my_rutie_math<\/span><span class=\"p\">,<\/span> <span class=\"ss\">lib_path: <\/span><span class=\"s2\">\"target\/release\"<\/span><span class=\"p\">).<\/span><span class=\"nf\">init<\/span> <span class=\"s2\">\"Init_mymath\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">__dir__<\/span>\r\n\r\n<span class=\"nb\">p<\/span> <span class=\"no\">MyMath<\/span><span class=\"p\">.<\/span><span class=\"nf\">hypot3<\/span><span class=\"p\">(<\/span><span class=\"mf\">1.0<\/span><span class=\"p\">,<\/span> <span class=\"mf\">2.0<\/span><span class=\"p\">,<\/span> <span class=\"mf\">3.0<\/span><span class=\"p\">)<\/span>\r\n<span class=\"c1\"># =&gt; 3.7416573867739413<\/span>\r\n\r\n<span class=\"c1\"># \u53c2\u8003<\/span>\r\n<span class=\"nb\">p<\/span> <span class=\"no\">Math<\/span><span class=\"p\">.<\/span><span class=\"nf\">sqrt<\/span><span class=\"p\">(<\/span><span class=\"mi\">1<\/span> <span class=\"o\">*<\/span> <span class=\"mi\">1<\/span> <span class=\"o\">+<\/span> <span class=\"mi\">2<\/span> <span class=\"o\">*<\/span> <span class=\"mi\">2<\/span> <span class=\"o\">+<\/span> <span class=\"mi\">3<\/span> <span class=\"o\">*<\/span> <span class=\"mi\">3<\/span><span class=\"p\">)<\/span>\r\n<span class=\"c1\"># =&gt; 3.7416573867739413<\/span>\r\n<\/code><\/pre>\n<p>1 \u30d5\u30a1\u30a4\u30eb\u3067\u793a\u305d\u3046\u3068\u3057\u3066\uff0c\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f \u3044\u304d\u306a\u308a gem &#8220;rutie&#8221;, &#8220;~&gt; 0.0.4&#8221; \u3068\u3084\u3063\u3066\u3044\u308b\u304c\uff0c\u3075\u3064\u3046\u306f Gemfile \u306b\u66f8\u304f\u3060\u308d\u3046\u3002<\/p>\n<p>\u3055\u3066\uff0crutie gem \u306e\u4f7f\u3044\u65b9\u3060\u304c\uff0c\u307e\u305a\u6700\u521d\u306b Rutie.new \u3067 Ruby \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308b\u3088\u3046\u3060\u3002<br \/>\n\u7b2c\u4e00\u5f15\u6570\u306b :my_rutie_math \u3068\u66f8\u3044\u305f\u304c\uff0c\u3053\u308c\u306f Rust \u3067\u4f5c\u3063\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u306e\u540d\u524d\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\uff0c\u6700\u521d\u306b cargo new \u3057\u305f\u3068\u304d\u306b\u4e0e\u3048\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u304c\u305d\u306e\u307e\u307e\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u540d\u306b\u306a\u3063\u3066\u3044\u308b\u3002<br \/>\n\u3057\u304b\u3057\uff0cCargo.toml \u306e [lib] \u306e\u3068\u3053\u308d\u3067<\/p>\n<pre class=\"post-pre\"><code><span class=\"nn\">[lib]<\/span>\r\n<span class=\"py\">name<\/span> <span class=\"p\">=<\/span> <span class=\"s\">\"hoge\"<\/span>\r\n<\/code><\/pre>\n<p>\u306e\u3088\u3046\u306b name \u3092\u4e0e\u3048\u3066\u3084\u308c\u3070\uff0c\u305d\u308c\u304c\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u540d\u306b\u306a\u308b\u306f\u305a\u3002<br \/>\n\u305d\u3057\u3066\uff0c\u305d\u308c\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u51fa\u6765\u305f\u6210\u679c\u7269\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u53cd\u6620\u3055\u308c\u308b\u306f\u305a\u3060\u3002<\/p>\n<p>\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u5f15\u6570\u306e lib_path \u306b\u3064\u3044\u3066\u306f\u3042\u3068\u3067\u89e6\u308c\u308b\u3002<\/p>\n<p>\u3068\u3082\u304b\u304f\uff0c\u305d\u3046\u3084\u3063\u3066\u51fa\u6765\u305f Rutie \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e init \u3092\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u7b2c\u4e00\u5f15\u6570\u306e &#8220;Init_mymath&#8221; \u306f\uff0c\u79c1\u304c\u300c\u521d\u671f\u5316\u95a2\u6570\u300d\u3068\u4eee\u306b\u547c\u3093\u3060\u30a2\u30ec\u306e\u540d\u524d\u3002<br \/>\n\u7b2c\u4e8c\u5f15\u6570\u306f\u3059\u3050\u3042\u3068\u3067\u89e6\u308c\u308b\u3002<\/p>\n<p>\u3068\u3082\u304b\u304f\uff0c\u3053\u3046\u3084\u3063\u3066 init \u3059\u308b\u3068\uff0cRutie \u3055\u3093\u304c\u4f7f\u3046\u3079\u304d\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u30d5\u30a1\u30a4\u30eb libmy_rutie_math.dylib \u3092\u898b\u3064\u3051\u3066 Init_mymath \u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3066\u304f\u308c\u308b\u308f\u3051\u3060\u3002<br \/>\n\u7e70\u308a\u8fd4\u3057\u306b\u306a\u308b\u304c\uff0c\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u62e1\u5f35\u5b50\u306f\u30bf\u30fc\u30b2\u30c3\u30c8\u306b\u3088\u3063\u3066\u7570\u306a\u308b\u3002<br \/>\nRutie \u3055\u3093\u306f\u305d\u306e\u3078\u3093\u3082\u3046\u307e\u304f\u8003\u3048\u3066\u898b\u3064\u3051\u3066\u304f\u308c\u308b\u306e\u3060\u3002<\/p>\n<p>\u3067\uff0c\u305d\u306e\u898b\u3064\u3051\u308b\u5834\u6240\u306a\u3093\u3060\u3051\u3069\u3082\uff0c\u3061\u3087\u3063\u3068\u3084\u3084\u3053\u3057\u3044\u3002<br \/>\n\u307e\u305a\uff0cinit \u306e\u7b2c\u4e8c\u5f15\u6570\u3092\u57fa\u6e96\u306b\u3057\u3066\uff0c\u305d\u3053\u304b\u3089\uff0clib_path \u306b\u4e0e\u3048\u305f\u76f8\u5bfe\u30d1\u30b9\u3060\u3051\u79fb\u52d5\u3057\u305f\u3068\u3053\u308d\u306b\u3042\u308b\uff0c\u3068\u898b\u308b\u306e\u3067\u3042\u308b\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306e\u5834\u5408\uff0cRuby \u30b9\u30af\u30ea\u30d7\u30c8\u306f Rust \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30eb\u30fc\u30c8\u306b\u7f6e\u3044\u305f\u304b\u3089\uff0c__dir__ \u306f\u305d\u3053\u3002<br \/>\n\u3067\uff0c\u305d\u3053\u304b\u3089\u898b\u305f target\/release \u306b\u30d5\u30a1\u30a4\u30eb\u3092\u898b\u51fa\u3059\u308f\u3051\u3002<\/p>\n<p>lib_path \u3084\u4ed6\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4e0e\u3048\u306a\u304b\u3063\u305f\u5834\u5408\uff0c&#8221;..\/target\/release&#8221; \u306b\u306a\u308b\u3002<br \/>\n\u4eca\u306e\u5834\u5408\uff0c\u3053\u308c\u3060\u3068\u90fd\u5408\u304c\u60aa\u3044\u306e\u3067 lib_path \u3092\u6307\u5b9a\u3057\u305f\u3002<\/p>\n<h2>\u4f7f\u3046<\/h2>\n<p>\u4f7f\u3044\u65b9\u306f\u7c21\u5358\u3002\u30b3\u30fc\u30c9\u4f8b\u306e\u3068\u304a\u308a\u3002<br \/>\nMyMath \u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u7279\u7570\u30e1\u30bd\u30c3\u30c9 hypot3 \u304c\u751f\u3048\u3066\u3044\u308b\u306e\u3067\uff0c\u305d\u308c\u3092\u3075\u3064\u3046\u306b\u547c\u3076\u3060\u3051\u3002<br \/>\n\u78ba\u8a8d\u306e\u305f\u3081 Math.sqrt(1 * 1 + 2 * 2 + 3 * 3) \u3082\u8868\u793a\u3057\u3066\u3044\u308b\u304c\uff0c\u540c\u3058\u6570\u5024\u304c\u5f97\u3089\u308c\u305f\u3002<\/p>\n<p>\u305f\u3060\u3057\uff0c\u4e00\u3064\u6ce8\u610f\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u3042\u308b\u3002<br \/>\nhypot3 \u306e\u5f15\u6570\u306f\u4e09\u3064\u3068\u3082 Float \u3067\u3042\u308b\uff0c\u3068\uff08Rust \u5074\u3067\uff09\u6c7a\u3081\u305f\u3002<br \/>\n\u3082\u3057\uff0cMyMath.hypot3 \u306b Integer \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4e0e\u3048\u305f\u3089\u3069\u3046\u306a\u308b\u306e\u304b\uff1f<\/p>\n<p>\u3084\u3063\u3066\u307f\u305f\u3002\u6b7b\u3093\u3060\u3002\u3044\u308f\u3086\u308b panic \u3068\u3044\u3046\u3084\u3064\u3060\u3002<br \/>\nFloat \u4ee5\u5916\u306e\u7269\u3092\u98df\u308f\u305b\u308b\u3068 x.unwrap() \u306e\u7b87\u6240\u3067\u6b7b\u306c\u306e\u3060\u3002<br \/>\n\u3082\u3061\u308d\u3093\uff0cRust \u5074\u3067\uff0c\u3044\u304d\u306a\u308a unwrap() \u3058\u3083\u306a\u304f\u3066\uff0cOk \u3068 Err \u3067\u5834\u5408\u5206\u3051\u3057\u3066\u3084\u308c\u3070\u6b7b\u306a\u306a\u3044\u95a2\u6570\u306b\u3067\u304d\u308b\u3002<br \/>\n\u3042\u308b\u3044\u306f Ruby \u5074\u3067\uff0cFloat \u306b\u578b\u30ad\u30e3\u30b9\u30c8\u3057\u3066\u547c\u3076\u3088\u3046\u306b\u3059\u308c\u3070\u554f\u984c\u306a\u3044\u3002<\/p>\n<h1>\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u30c6\u30b9\u30c8<\/h1>\n<p>\u524d\u56de\uff08Ruby\/Rust \u9023\u643a (3)\u3000FFI \u3067\u6570\u5024\u8a08\u7b97\uff09\u306f\uff0cFFI \u3092\u76f4\u306b\u4f7f\u3046\u3084\u308a\u65b9\u3067 hypot3 \u3092\u3084\u3063\u3066\u307f\u3066\uff0c\u300cRust \u3092\u547c\u3076\u3088\u308a Ruby \u3067\u66f8\u3044\u305f\u307b\u3046\u304c\u305a\u3063\u3068\u901f\u304b\u3063\u305f\u300d\u3068\u3044\u3046\u6b8b\u5ff5\u306a\u7d50\u679c\u3092\u5f97\u305f\u3002<\/p>\n<p>Rutie \u7248\u306f\u3069\u3046\u3060\u308d\u3046\u304b\u3002\u3042\u307e\u308a\u671f\u5f85\u3057\u306a\u3044\u3067\u3084\u3063\u3066\u307f\u3088\u3046\u3002<\/p>\n<h2>\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9<\/h2>\n<p>\u4eca\u56de\u3082 benchmark_driver \u3068\u3044\u3046 gem \u3092\u4f7f\u3063\u3066\u8a08\u6e2c\u3059\u308b\u3002<\/p>\n<p>\u3042\u3089\u304b\u3058\u3081<\/p>\n<pre class=\"post-pre\"><code>gem i benchmark_driver\r\n<\/code><\/pre>\n<p>\u3068\u3084\u3063\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3002<br \/>\n\uff08\u3088\u304f\u6df7\u4e71\u3059\u308b\u3051\u3069\uff0cgem \u540d\u306f\u30cf\u30a4\u30d5\u30f3\u3058\u3083\u306a\u304f\u3066\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\uff09<\/p>\n<p>\u4eca\u56de\u306f\u524d\u56de\u3068\u9055\u3063\u3066\uff0c\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092 Ruby \u3067\u66f8\u3044\u3066\u3084\u3063\u3066\u307f\u308b\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u6c17\u3092\u3064\u3051\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u304c\uff0c\u3055\u304d\u307b\u3069\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u306f\u30b3\u30b3\u3092\u8868\u3059\u306e\u306b __dir__ \u3092\u4f7f\u3063\u305f\u306e\u3060\u304c\uff0cbenchmark_driver \u3067\u305d\u3046\u66f8\u304f\u3068\uff0c\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5c45\u5834\u6240\u3067\u306f\u306a\u304f\uff0cbenchmark_driver \u304c\u751f\u6210\u3059\u308b\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u306e\u5c45\u5834\u6240\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\uff0cRust \u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u304c\u898b\u3064\u3051\u3089\u308c\u306a\u304f\u306a\u308b\uff0c\u3068\u3044\u3046\u3053\u3068\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u305d\u3053\u3092\u4e00\u5de5\u592b\u3057\u305f\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nb\">require<\/span> <span class=\"s2\">\"benchmark_driver\"<\/span>\r\n\r\n<span class=\"no\">Benchmark<\/span><span class=\"p\">.<\/span><span class=\"nf\">driver<\/span> <span class=\"k\">do<\/span> <span class=\"o\">|<\/span><span class=\"n\">r<\/span><span class=\"o\">|<\/span>\r\n  <span class=\"n\">r<\/span><span class=\"p\">.<\/span><span class=\"nf\">prelude<\/span> <span class=\"o\">&lt;&lt;~<\/span><span class=\"no\">EOT<\/span><span class=\"sh\">\r\n    gem \"rutie\", \"~&gt; 0.0.4\"\r\n    require \"rutie\"\r\n\r\n    Rutie.new(:my_rutie_math, lib_path: \"target\/release\").init \"Init_mymath\", \"<\/span><span class=\"si\">#{<\/span><span class=\"n\">__dir__<\/span><span class=\"si\">}<\/span><span class=\"sh\">\"\r\n<\/span><span class=\"no\">  EOT<\/span>\r\n\r\n  <span class=\"n\">r<\/span><span class=\"p\">.<\/span><span class=\"nf\">report<\/span> <span class=\"s2\">\"MyMath.hypot3(1.0, 2.0, 3.0)\"<\/span>\r\n  <span class=\"n\">r<\/span><span class=\"p\">.<\/span><span class=\"nf\">report<\/span> <span class=\"s2\">\"Math.sqrt(1.0 * 1.0 + 2.0 * 2.0 + 3.0 * 3.0)\"<\/span>\r\n<span class=\"k\">end<\/span>\r\n<\/code><\/pre>\n<p>prelude \u306f\uff0c\u8a08\u6e2c\u306b\u5148\u7acb\u3063\u3066\u3084\u3063\u3066\u304a\u304f\u3053\u3068\u3092\u66f8\u304f\u3002<br \/>\nreport \u306f\u8a08\u6e2c\u3057\u305f\u3044\u51e6\u7406\u3092\u66f8\u304f\u3002<\/p>\n<h2>\u30c6\u30b9\u30c8\u5b9f\u884c<\/h2>\n<p>\u3055\u304d\u307b\u3069\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3068\uff1a<\/p>\n<pre class=\"post-pre\"><code>Math.sqrt(1.0 * 1.0 + 2.0 * 2.0 + 3.0 * 3.0):  11796989.3 i\/s\r\n                MyMath.hypot3(1.0, 2.0, 3.0):   5684591.1 i\/s - 2.08x  slower\r\n<\/code><\/pre>\n<p>\u3056\uff0c\u60e8\u6557\u3067\u3059\u3084\u3093\u3002<br \/>\nRutie \u7248\u306e\u5b9f\u884c\u901f\u5ea6\u306f\u524d\u56de\u306e FFI \u7248\u3068\u307b\u307c\u540c\u3058\u3002Ruby \u3067\u66f8\u3044\u305f\u306e\u306e\u500d\u306e\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u3042\u306e\uff0c\u4eca\u65e5\u306f\u3082\u3046\u5bdd\u3066\u3044\u3044\u3059\u304b\uff1f<br \/>\n\u6b21\u306f\u3082\u3063\u3068\u91cd\u3044\u51e6\u7406\u3092 Rust \u306b\u3084\u3089\u305b\u3066 Ruby \u30b9\u30af\u30ea\u30d7\u30c8\u306e\u9f3b\u3092\u660e\u304b\u3057\u3066\u3084\u308a\u307e\u3059\u3093\u3067\u3002<\/p>\n<div>\n<p>macOS \u3068\uff0cWindows \u306e msvc \u304a\u3088\u3073 gnu \u3067\u8a66\u3057\u305f\u304c\uff0c\u3044\u305a\u308c\u3082\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306e\u30ea\u30f3\u30af\u306e\u6bb5\u968e\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3002\u8a73\u3057\u304f\u306f\u8abf\u3079\u3066\u3044\u306a\u3044\u304c\uff0c\u6a5f\u4f1a\u304c\u3042\u308c\u3070\u5225\u8a18\u4e8b\u306b\u307e\u3068\u3081\u305f\u3044\u3002\u00a0\u21a9<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Ruby\/Rust \u9023\u643a (1)\u3000\u76ee\u7684 &nbsp; Ruby\/Rust \u9023\u643a (2)\u3000\u624b\u6bb5 &nbsp; R [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-45331","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>- Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:description\" content=\"Ruby\/Rust \u9023\u643a (1)\u3000\u76ee\u7684 &nbsp; Ruby\/Rust \u9023\u643a (2)\u3000\u624b\u6bb5 &nbsp; R [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-28T08:59:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T01:45:40+00:00\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/\",\"name\":\"- Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-05-28T08:59:21+00:00\",\"dateModified\":\"2024-04-30T01:45:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"- Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/","og_locale":"zh_CN","og_type":"article","og_description":"Ruby\/Rust \u9023\u643a (1)\u3000\u76ee\u7684 &nbsp; Ruby\/Rust \u9023\u643a (2)\u3000\u624b\u6bb5 &nbsp; R [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-05-28T08:59:21+00:00","article_modified_time":"2024-04-30T01:45:40+00:00","author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/","name":"- Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-05-28T08:59:21+00:00","dateModified":"2024-04-30T01:45:40+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/45331-2\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/45331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=45331"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/45331\/revisions"}],"predecessor-version":[{"id":91166,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/45331\/revisions\/91166"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=45331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=45331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=45331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}