{"id":201,"date":"2026-04-01T11:56:55","date_gmt":"2026-04-01T03:56:55","guid":{"rendered":"https:\/\/www.handytoo.com\/?p=201"},"modified":"2026-04-01T11:56:56","modified_gmt":"2026-04-01T03:56:56","slug":"%f0%9f%93%8c-rust%e5%80%9f%e7%94%a8%e6%9c%ba%e5%88%b6%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a%e6%89%80%e6%9c%89%e6%9d%83%e3%80%81%e5%bc%95%e7%94%a8%e4%b8%8e%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f","status":"publish","type":"post","link":"https:\/\/www.handytoo.com\/?p=201","title":{"rendered":"\ud83d\udccc Rust\u501f\u7528\u673a\u5236\u6df1\u5ea6\u89e3\u6790\uff1a\u6240\u6709\u6743\u3001\u5f15\u7528\u4e0e\u751f\u547d\u5468\u671f\u7684\u6838\u5fc3\u5173\u7cfb\u603b\u7ed3"},"content":{"rendered":"\n<p><strong>\u4e00\u53e5\u8bdd\u6838\u5fc3\uff1a<\/strong><br><strong>\u201c\u6240\u6709\u6743\u51b3\u5b9a\u6570\u636e\u5f52\u5c5e\uff0c\u501f\u7528\u63a7\u5236\u4e34\u65f6\u8bbf\u95ee\uff1b\u53ef\u53d8\/\u4e0d\u53ef\u53d8\u7ed1\u5b9a\u7ba1\u53d8\u91cf\u7075\u6d3b\u5ea6\uff0c<\/strong><code>&amp;<\/code><strong>\/<\/strong><code>&amp;mut<\/code>** \u5b9a\u6570\u636e\u8bfb\u5199\u6743\u3002\u201d**<\/p>\n\n\n\n<p><strong>\u4e00\u3001\u6240\u6709\u6743\u4e0e\u501f\u7528\u89c4\u5219\uff08\u57fa\u7840\uff09<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6240\u6709\u6743<\/strong>\uff1a\u6570\u636e\u6709\u552f\u4e00\u4e3b\u4eba\uff0c<code>move<\/code> \u8f6c\u79fb\u6240\u6709\u6743\uff0c\u8d85\u51fa\u4f5c\u7528\u57df\u81ea\u52a8\u91ca\u653e\u3002<\/li>\n\n\n\n<li><strong>\u501f\u7528<\/strong>\uff1a\u901a\u8fc7\u5f15\u7528 <code>&amp;T<\/code> \u6216 <code>&amp;mut T<\/code> \u4e34\u65f6\u4f7f\u7528\u6570\u636e\uff0c\u4e0d\u8f6c\u79fb\u6240\u6709\u6743\u3002<\/li>\n\n\n\n<li><strong>\u501f\u7528\u94c1\u5f8b<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u53ef\u53d8\u501f\u7528\u53ef\u5171\u4eab<\/strong>\uff1a\u591a\u4e2a <code>&amp;T<\/code> \u540c\u65f6\u5b58\u5728\u3002<\/li>\n\n\n\n<li><strong>\u53ef\u53d8\u501f\u7528\u72ec\u5360<\/strong>\uff1a\u540c\u4e00\u4f5c\u7528\u57df\u5185\u53ea\u80fd\u6709\u4e00\u4e2a <code>&amp;mut T<\/code>\uff0c\u4e14\u4e0d\u80fd\u6709 <code>&amp;T<\/code> \u5171\u5b58\u3002<\/li>\n\n\n\n<li><strong>\u4f5c\u7528\u57df\u9650\u5b9a<\/strong>\uff1a\u501f\u7528\u5fc5\u987b\u665a\u4e8e\u88ab\u501f\u7528\u6570\u636e\u521b\u5efa\uff0c\u65e9\u4e8e\u6570\u636e\u91ca\u653e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>\u4e8c\u3001\u53ef\u53d8 vs \u4e0d\u53ef\u53d8\u7ed1\u5b9a\uff08\u5173\u952e\u533a\u5206\uff09<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7ed1\u5b9a\u7c7b\u578b<\/th><th>\u8bed\u6cd5<\/th><th>\u6bd4\u55bb<\/th><th>\u6743\u9650\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>\u4e0d\u53ef\u53d8\u7ed1\u5b9a<\/td><td><code>let x = &amp;data;<\/code><\/td><td>\u710a\u6b7b\u7684\u53ea\u8bfb\u5361<\/td><td>\u2460 \u53d8\u91cf <code>x<\/code> \u4e0d\u80fd\u6539\u6307\u5411 \u2461 \u4e0d\u80fd\u901a\u8fc7 <code>x<\/code> \u4fee\u6539\u6570\u636e (<code>*x = ...<\/code> \u62a5\u9519)<\/td><\/tr><tr><td>\u53ef\u53d8\u7ed1\u5b9a<\/td><td><code>let mut x = &amp;data;<\/code><\/td><td>\u53ef\u6362\u4e66\u7684\u53ea\u8bfb\u5361<\/td><td>\u2460 \u53ef\u6539 <code>x<\/code> \u6307\u5411 (<code>x = &amp;new_data<\/code>) \u2461 \u4ecd\u4e0d\u80fd\u6539\u6570\u636e<\/td><\/tr><tr><td>\u53ef\u53d8\u5f15\u7528<\/td><td><code>let x = &amp;mut data;<\/code><\/td><td>\u710a\u6b7b\u7684\u7f16\u8f91\u7b14<\/td><td>\u2460 \u53d8\u91cf <code>x<\/code> \u4e0d\u80fd\u6539\u6307\u5411 \u2461 \u53ef\u901a\u8fc7 <code>*x<\/code> \u4fee\u6539\u6570\u636e<\/td><\/tr><tr><td>\u53ef\u53d8\u7ed1\u5b9a + \u53ef\u53d8\u5f15\u7528<\/td><td><code>let mut x = &amp;mut data;<\/code><\/td><td>\u53ef\u6362\u4e66\u7684\u7f16\u8f91\u7b14<\/td><td>\u2460 \u53ef\u6539 <code>x<\/code> \u6307\u5411 (<code>x = &amp;mut new_data<\/code>) \u2461 \u53ef\u6539\u6570\u636e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u4e09\u3001\u89e3\u5f15\u7528\uff08Dereferencing\uff09<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u64cd\u4f5c<\/strong>\uff1a\u7528 <code>*<\/code> \u64cd\u4f5c\u7b26\u901a\u8fc7\u5f15\u7528\u83b7\u53d6\u539f\u59cb\u6570\u636e\uff08\u5982 <code>*x<\/code> \u83b7\u53d6 <code>x: &amp;T<\/code> \u80cc\u540e\u7684 <code>T<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7528\u9014<\/strong>\uff1a\u901a\u8fc7\u5f15\u7528\u4fee\u6539\u6570\u636e\uff08\u5982 <code>*x = 5;<\/code>\uff09\u6216\u8c03\u7528\u65b9\u6cd5\uff08\u7f16\u8bd1\u5668\u5e38\u81ea\u52a8\u89e3\u5f15\u7528\uff09\u3002<\/li>\n\n\n\n<li><strong>\u6bd4\u55bb<\/strong>\uff1a\u6309\u85cf\u5b9d\u56fe (<code>&amp;<\/code>) \u6316\u51fa\u5b9d\u85cf (<code>*<\/code>)\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u56db\u3001\u8bb0\u5fc6\u53e3\u8bc0\u4e0e\u5b9e\u6218\u6280\u5de7<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u201c\u4e00\u4e3b\u591a\u8bfb\uff0c\u4e00\u5199\u72ec\u5360\u201d<\/strong> \uff1a\u4e00\u4e2a\u6570\u636e\u53ef\u591a\u8bfb (<code>&amp;<\/code>)\uff0c\u4f46\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u88ab\u4e00\u4e2a\u5199 (<code>&amp;mut<\/code>)\u3002<\/li>\n\n\n\n<li>**\u9ed8\u8ba4\u9009 **<code>&amp;<\/code>\uff1a\u4f18\u5148\u4f7f\u7528\u4e0d\u53ef\u53d8\u5f15\u7528\uff0c\u66f4\u5b89\u5168\u3002<\/li>\n\n\n\n<li><code>mut<\/code>** \u53cc\u542b\u4e49**\uff1a\n<ul class=\"wp-block-list\">\n<li><code>let mut x<\/code>: \u5141\u8bb8\u53d8\u91cf <code>x<\/code> <strong>\u6362\u7ed1\u5b9a<\/strong>\uff08\u6307\u5411\u5176\u4ed6\u6570\u636e\uff09\u3002<\/li>\n\n\n\n<li><code>&amp;mut<\/code>: \u5141\u8bb8 <strong>\u4fee\u6539\u6570\u636e<\/strong>\uff0c\u4f46\u53d8\u91cf\u672c\u8eab\u4ecd\u662f\u4e0d\u53ef\u53d8\u7ed1\u5b9a\uff08\u9664\u975e\u518d\u52a0 <code>let mut<\/code>\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u62a5\u9519\u6392\u67e5<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u65e0\u6cd5\u4fee\u6539\u6570\u636e\uff1f\u68c0\u67e5\u662f\u5426\u6709 <code>&amp;mut<\/code>\u3002<\/li>\n\n\n\n<li>\u7f16\u8bd1\u62a5\u9519\u201c\u5df2\u5b58\u5728\u53ef\u53d8\u501f\u7528\u201d\uff1f\u68c0\u67e5\u4f5c\u7528\u57df\u5185\u662f\u5426\u6709\u91cd\u53e0\u7684\u53ef\u53d8\u5f15\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>\u4e94\u3001\u751f\u547d\u5468\u671f\uff08\u7b80\u8981\uff09<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f15\u7528\u4e0d\u80fd\u8d85\u8fc7\u88ab\u5f15\u7528\u6570\u636e\u7684\u751f\u547d\u5468\u671f\uff08\u5982\u51fd\u6570\u5185\u4e34\u65f6\u53d8\u91cf\u4e0d\u80fd\u4f5c\u4e3a\u8fd4\u56de\u503c\u5f15\u7528\uff09\uff0c\u4f46 Rust \u901a\u8fc7\u751f\u547d\u5468\u671f\u6ce8\u89e3\u81ea\u52a8\u68c0\u67e5\uff0c\u591a\u6570\u60c5\u51b5\u65e0\u9700\u624b\u52a8\u6807\u6ce8\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\ud83d\udd25 \u7ec8\u6781\u53e3\u8bc0\uff1a<\/strong><br><strong>\u201c\u6240\u6709\u6743\u662f\u6839\uff0c\u501f\u7528\u662f\u679d\uff1b\u53ef\u53d8\u4e0d\u53ef\u53d8\uff0c\u7ed1\u5b9a\u548c\u5f15\u7528\u8981\u5206\u6e05\uff1b\u89e3\u5f15\u7528\u6316\u6570\u636e\uff0c\u89c4\u5219\u5b88\u597d\u4e0d\u614c\u5f20\uff01\u201d<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u53e5\u8bdd\u6838\u5fc3\uff1a\u201c\u6240\u6709\u6743\u51b3\u5b9a\u6570\u636e\u5f52\u5c5e\uff0c\u501f\u7528\u63a7\u5236\u4e34\u65f6\u8bbf\u95ee\uff1b\u53ef\u53d8\/\u4e0d\u53ef\u53d8\u7ed1\u5b9a\u7ba1\u53d8\u91cf\u7075\u6d3b\u5ea6\uff0c&amp;\/&amp;mut [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-201","post","type-post","status-publish","format-standard","hentry","category-rust"],"_links":{"self":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=201"}],"version-history":[{"count":1,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/201\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/201\/revisions\/202"}],"wp:attachment":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}