{"id":9335,"date":"2022-10-10T19:00:00","date_gmt":"2022-10-10T10:00:00","guid":{"rendered":"https:\/\/taki-lab.site\/bocci\/?p=9335"},"modified":"2022-10-09T12:04:19","modified_gmt":"2022-10-09T03:04:19","slug":"rust%e5%8b%89%e5%bc%b7%e4%b8%ad%e3%80%8110-9%e3%81%ae%e7%a9%8d%e3%81%bf%e4%b8%8a%e3%81%92","status":"publish","type":"post","link":"https:\/\/taki-lab.site\/bocci\/?p=9335","title":{"rendered":"RUST\u52c9\u5f37\u4e2d\u300110\/9\u306e\u7a4d\u307f\u4e0a\u3052"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f wp-block-embed-\u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"lOTNyJfVCl\"><a href=\"https:\/\/taki-lab.site\/bocci\/?p=9271\">RUST\u52c9\u5f37\u4e2d\u300110\/2\u306e\u7a4d\u307f\u4e0a\u3052?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;RUST\u52c9\u5f37\u4e2d\u300110\/2\u306e\u7a4d\u307f\u4e0a\u3052?&#8221; &#8212; \u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f\" src=\"https:\/\/taki-lab.site\/bocci\/?p=9271&#038;embed=true#?secret=o7uBf1cLCA#?secret=lOTNyJfVCl\" data-secret=\"lOTNyJfVCl\" width=\"474\" height=\"267\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u524d\u56de\u306e\u7d9a\u304d\u3067\u3001Rust\u5074\u306e\u5b9f\u88c5\u3092\u884c\u3063\u3066\u884c\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;package]\nname = \"mandelbrot\"\nversion = \"0.1.0\"\nauthors = &#91;\"taki\"]\nedition = \"2018\"\n\n&#91;lib]\ncrate-type = &#91;\"cdylib\", \"rlib\"]\n\n&#91;features]\ndefault = &#91;\"console_error_panic_hook\"]\n\n&#91;dependencies]\njs-sys = \"0.3.60\"\nwasm-bindgen = \"0.2.63\"\n\n# The `console_error_panic_hook` crate provides better debugging of panics by\n# logging them with `console.error`. This is great for development, but requires\n# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for\n# code size when deploying.\nconsole_error_panic_hook = { version = \"0.1.6\", optional = true }\n\n# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size\n# compared to the default allocator's ~10K. It is slower than the default\n# allocator, however.\n#\n# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.\nwee_alloc = { version = \"0.4.5\", optional = true }\n\n&#91;dependencies.web-sys]\nversion = \"0.3.60\"\nfeatures = &#91;\n    'CanvasRenderingContext2d',\n    'Document',\n    'Element',\n    'HtmlCanvasElement',\n    'ImageData',\n    'Performance',\n    'Window',\n]\n\n&#91;dev-dependencies]\nwasm-bindgen-test = \"0.3.13\"\n\n&#91;profile.release]\n# Tell `rustc` to optimize for small code size.\nopt-level = \"s\"\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mod utils;\nmod logic;\n\nuse wasm_bindgen::prelude::*;\nuse wasm_bindgen::{Clamped, JsCast};\nuse web_sys::ImageData;\n\n\/\/ When the `wee_alloc` feature is enabled, use `wee_alloc` as the global\n\/\/ allocator.\n#&#91;cfg(feature = \"wee_alloc\")]\n#&#91;global_allocator]\nstatic ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n\n#&#91;wasm_bindgen]\nextern \"C\" {\n    #&#91;wasm_bindgen(js_namespace = console)]\n    fn log(a: &amp;str);\n}\n\nmacro_rules! console_log {\n    ($($t:tt)*) =&gt; (log(&amp;format_args!($($t)*).to_string()))\n}\n\nmacro_rules! measure_elapsed_time {\n    ($t:tt,$s:block) =&gt; {{\n        let window = web_sys::window().expect(\"should have a window in this context\");\n        let performance = window\n            .performance()\n            .expect(\"performance should be available\");\n        let start = performance.now();\n        let result = { $s };\n        let end = performance.now();\n        console_log!(\"{}:{}&#91;ms]\", $t, end - start);\n        result\n    }};\n}\n\n#&#91;wasm_bindgen]\npub fn generate_mandelbrot_set(\n    canvas_w: usize,\n    canvas_h: usize,\n    x_min: f64,\n    x_max: f64,\n    y_min: f64,\n    y_max: f64,\n    max_iter: usize,\n) -&gt; Vec&lt;u8&gt; {\n    measure_elapsed_time!(\"generate:wasm\\telapsed:\", {\n        logic::generate_mandelbrot_set(canvas_w, canvas_h,\n            x_min, x_max, y_min, y_max, max_iter)\n    })\n}\n\n#&#91;wasm_bindgen]\npub fn draw_mandelbrot_set() {\n    const CANVAS_ID: &amp;str = \"canvas_wasm\";\n    let document = web_sys::window().unwrap().document().unwrap();\n    let canvas = document.get_element_by_id(CANVAS_ID).unwrap();\n    let canvas: web_sys::HtmlCanvasElement = canvas\n        .dyn_into::&lt;web_sys::HtmlCanvasElement&gt;()\n        .map_err(|_| ())\n        .unwrap();\n    let context = canvas\n        .get_context(\"2d\")\n        .unwrap()\n        .unwrap()\n        .dyn_into::&lt;web_sys::CanvasRenderingContext2d&gt;()\n        .unwrap();\n    let canvas_w = canvas.width() as usize;\n    let canvas_h = canvas.height() as usize;\n    const X_MIN: f64 = -1.5;\n    const X_MAX: f64 = 0.5;\n    const Y_MIN: f64 = -1.0;\n    const Y_MAX: f64 = 1.0;\n    const MAX_ITER: usize = 64;\n\n    let mut result = measure_elapsed_time!(\"generate:wasm\\telapsed:\", {\n        logic::generate_mandelbrot_set(canvas_w, canvas_h,\n            X_MIN, X_MAX, Y_MIN, Y_MAX, MAX_ITER)\n    });\n    measure_elapsed_time!(\"draw:wasm\\telapsed:\", {\n        let data = ImageData::new_with_u8_clamped_array_and_sh(\n            Clamped(&amp;mut result),\n            canvas.width(),\n            canvas.height(),\n        );\n        if let Ok(data) = data {\n            let _ = context.put_image_data(&amp;data, 0.0, 0.0);\n        }\n    })\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"487\" data-attachment-id=\"9337\" data-permalink=\"https:\/\/taki-lab.site\/bocci\/?attachment_id=9337\" data-orig-file=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?fit=1820%2C1872&amp;ssl=1\" data-orig-size=\"1820,1872\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2022-10-09-115023\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?fit=474%2C487&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=474%2C487&#038;ssl=1\" alt=\"\" class=\"wp-image-9337\" srcset=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=996%2C1024&amp;ssl=1 996w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=292%2C300&amp;ssl=1 292w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=768%2C790&amp;ssl=1 768w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?resize=1493%2C1536&amp;ssl=1 1493w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?w=1820&amp;ssl=1 1820w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-09-115023.png?w=1422&amp;ssl=1 1422w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<p>\u30de\u30b8\u75b2\u308c\u305f\u308f\u3002<\/p>\n\n\n\n<p>JavaScript\u5074\u3067\u30b9\u30da\u30eb\u30df\u30b9\u304c\u3042\u3063\u3066\u3001\u3046\u307e\u304fJS\u5074\u304b\u3089Rust\u306e\u51e6\u7406\u3092\u547c\u3073\u51fa\u305b\u306a\u3044\u3068\u3044\u3046\u30df\u30b9\u3092\u3084\u3089\u304b\u3057\u3066\u3001<\/p>\n\n\n\n<p>\u30b9\u30da\u30eb\u30df\u30b9\u306b\u6c17\u304c\u3064\u3044\u3066\u5bfe\u51e6\u3057\u3066\u52d5\u304b\u3059\u307e\u3067\u306b1\u6642\u9593\u3050\u3089\u3044\u304b\u304b\u3063\u305f\u304b\u306a\uff1f<\/p>\n\n\n\n<p>\u539f\u56e0\u3092\u63a2\u308b\u305f\u3081\u306bWinMarge\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u3092\u6bd4\u8f03\u3057\u3066\u3001\u3068\u8a00\u3046\u4f5c\u696d\u3092\u3084\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e\u7d9a\u304d\u3067\u3001Rust\u5074\u306e\u5b9f\u88c5\u3092\u884c\u3063\u3066\u884c\u304d\u307e\u3059\u3002 \u30de\u30b8\u75b2\u308c\u305f\u308f\u3002 JavaScript\u5074\u3067\u30b9\u30da\u30eb\u30df\u30b9\u304c\u3042\u3063\u3066\u3001\u3046\u307e\u304fJS\u5074\u304b\u3089Rust\u306e\u51e6\u7406\u3092\u547c\u3073\u51fa\u305b\u306a\u3044\u3068\u3044\u3046\u30df\u30b9\u3092\u3084\u3089\u304b\u3057\u3066\u3001 \u30b9\u30da\u30eb\u30df\u30b9\u306b\u6c17\u304c\u3064\u3044\u3066\u5bfe\u51e6\u3057\u3066\u52d5\u304b\u3059\u307e\u3067 &hellip; <a href=\"https:\/\/taki-lab.site\/bocci\/?p=9335\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">RUST\u52c9\u5f37\u4e2d\u300110\/9\u306e\u7a4d\u307f\u4e0a\u3052<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[2542,3],"tags":[],"class_list":["post-9335","post","type-post","status-publish","format-standard","hentry","category-rust","category-3"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8SDbY-2qz","jetpack-related-posts":[{"id":9154,"url":"https:\/\/taki-lab.site\/bocci\/?p=9154","url_meta":{"origin":9335,"position":0},"title":"RUST\u52c9\u5f37\u4e2d\u30019\/11\u306e\u7a4d\u307f\u4e0a\u3052?","author":"taki","date":"2022\u5e749\u670813\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=9103 \u524d\u56de\u306fcargo insta\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-11-085133.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-11-085133.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-11-085133.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":8638,"url":"https:\/\/taki-lab.site\/bocci\/?p=8638","url_meta":{"origin":9335,"position":1},"title":"RUST\u52c9\u5f37\u4e2d\u30016\/26\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e746\u670828\u65e5","format":false,"excerpt":"\u524d\u56de\u306e\u7d9a\u304d https:\/\/taki-lab.site\/bocci\/?p=8476 \u4eca\u56de\u306fthise\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8349,"url":"https:\/\/taki-lab.site\/bocci\/?p=8349","url_meta":{"origin":9335,"position":2},"title":"RUST\u52c9\u5f37\u4e2d\u30015\/14\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e745\u670816\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=8280 \u30a8\u30e9\u30fc\u306e\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u52c9\u5f37\u3002\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8476,"url":"https:\/\/taki-lab.site\/bocci\/?p=8476","url_meta":{"origin":9335,"position":3},"title":"RUST\u52c9\u5f37\u4e2d\u30016\/4\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e746\u67085\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=8454 \u524d\u56de\u306e\u7d9a\u304d\u3002 anyhow\u30af\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8454,"url":"https:\/\/taki-lab.site\/bocci\/?p=8454","url_meta":{"origin":9335,"position":4},"title":"RUST\u52c9\u5f37\u4e2d\u30015\/29\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e745\u670829\u65e5","format":false,"excerpt":"\u3042\u3001\u4eca\u65e5\u8089\u306e\u65e5\u3058\u3083\u3093\u3002 https:\/\/taki-lab.site\/bocci\/?p=8421 us\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8421,"url":"https:\/\/taki-lab.site\/bocci\/?p=8421","url_meta":{"origin":9335,"position":5},"title":"RUST\u52c9\u5f37\u4e2d\u30015\/21\u306e\u7a4d\u307f\u4e0a\u3052","author":"taki","date":"2022\u5e745\u670823\u65e5","format":false,"excerpt":"https:\/\/taki-lab.site\/bocci\/?p=8349 \u30a8\u30e9\u30fc\u306e\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u52c9\u5f37\u3002\u2026","rel":"","context":"Rust","block_context":{"text":"Rust","link":"https:\/\/taki-lab.site\/bocci\/?cat=2542"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/9335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9335"}],"version-history":[{"count":2,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/9335\/revisions"}],"predecessor-version":[{"id":9339,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/9335\/revisions\/9339"}],"wp:attachment":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}