{"id":8349,"date":"2024-06-12T20:01:01","date_gmt":"2024-06-12T12:01:01","guid":{"rendered":""},"modified":"2024-06-12T20:01:01","modified_gmt":"2024-06-12T12:01:01","slug":"rust \u51fd\u6570_rust\u8c03\u7528c++\u5e93","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8349.html","title":{"rendered":"rust \u51fd\u6570_rust\u8c03\u7528c++\u5e93"},"content":{"rendered":"
Rust\u6709\u4e24\u79cd\u57fa\u672c\u7684\u6d6e\u70b9\u7c7b\u578b\uff0c\u662ff32\u548cf64\uff0c\u5206\u522b\u4ee3\u886832\u7c7b\u548c64\u4f4d\u5927\u5c0f\uff0c\u9ed8\u8ba4\u6d6e\u70b9\u7c7b\u578b\u4e3af64,\u56e0\u4e3a\u5728\u73b0\u4ee3\u7684cpu\u4e0a\uff0c\u5b83\u7684\u901f\u5ea6\u4e0ef32\u5927\u81f4\u76f8\u540c\uff0c\u4f46\u5177\u6709\u66f4\u9ad8\u7684\u7cbe\u5ea6\u3002\u6240\u6709\u7684\u6d6e\u70b9\u7c7b\u578b\u90fd\u662f\u6709\u7b26\u53f7\u7684\u3002<\/p>\n
\u4e0b\u9762\u4ee3\u7801\u5c55\u793a\u6d6e\u70b9\u7c7b\u578b\u7684\u7528\u6cd5<\/p>\n
fn main() { let x = 2.0; \/\/ f64 let y: f32 = 3.0; \/\/ f32 }<\/code><\/pre>\n\u6d6e\u70b9\u7c7b\u578b\u9075\u5faaIEEE-754\u6807\u51c6,f32\u662f\u5355\u7cbe\u5ea6\u6d6e\u70b9\u7c7b\u578bf64\u662f\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u7c7b\u578b<\/p>\n
\u6570\u503c\u64cd\u4f5c<\/h4>\n
Rust\u6240\u6709\u6570\u636e\u7c7b\u578b\uff0c\u652f\u6301\u57fa\u672c\u7684\u6570\u5b66\u64cd\u4f5c\uff1a+,-,*,\/,%\u3002\u6574\u578b\u9664\u6cd5\u820d\u5230\u6700\u8fd1\u7684\u6574\u578b\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u663e\u793al\u8d4b\u503c\u7684\u6570\u5b57\u64cd\u4f5c\uff1a<\/p>\n
fn main() { \/\/ addition let sum = 5 + 10; \/\/ subtraction let difference = 95.5 - 4.3; \/\/ multiplication let product = 4 * 30; \/\/ division let quotient = 56.7 \/ 32.2; let floored = 2 \/ 3; \/\/ Results in 0 \/\/ remainder let remainder = 43 % 5;<\/code><\/pre>\n\u5728\u4e0a\u9762\u8bed\u53e5\u4e2d\u7684\u6bcf\u4e2a\u8868\u8fbe\u5f0f\u4f7f\u7528\u4e86\u6570\u5b66\u8fd0\u7b97\u7b26\u53bb\u5f97\u5230\u4e00\u4e2a\u5355\u503c\uff0c\u7136\u540e\u8d4b\u7ed9\u76f8\u5e94\u53d8\u91cf\uff0c\u9644\u5f55B\u662fRust\u63d0\u4f9b\u7684\u6240\u6709\u64cd\u4f5c\u7b26\u5217\u8868\u3002<\/p>\n
\u5e03\u5c14\u7c7b\u578b<\/h4>\n<\/p>\n
\u540c\u5176\u4ed6\u5927\u591a\u6570\u8bed\u8a00\u4e00\u6837\uff0cRust\u4e2d\u7684\u5e03\u5c14\u7c7b\u578b\u6709\u4e24\u4e2a\u503c true,false. \u5e03\u5c14\u53d8\u91cf\u5360\u7528\u4e00\u4e2a\u5b57\u8282\u3002Rust\u4e2d\u7684\u5e03\u5c14\u7c7b\u578b\u7528bool\u5173\u952e\u5b57\u6307\u5b9a\u3002<\/p>\n
fn main() { let t = true; let f: bool = false; \/\/ with explicit type annotation }<\/code><\/pre>\n\u4f7f\u7528bool\u7c7b\u578b\u573a\u666f\u4e3b\u8981\u662f\u6761\u4ef6\u5224\u65ad\uff0c\u5982\u5728if\u7684\u8868\u8fbe\u5f0f\u4e2d\uff0c\u6211\u4eec\u5728\u6d41\u7a0b\u63a7\u5236\u4e00\u8282\u4e2d\u8bf4\u660e\u600e\u6837\u4f7f\u7528if\u8868\u8fbe\u5f0f\u3002<\/p>\n
\u5b57\u7b26\u7c7b\u578b<\/h4>\n
Rust\u7684 char\u7c7b\u578b\u662f\u8bed\u8a00\u7684\u57fa\u672c\u5b57\u7b26\u7c7b\u578b\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u58f0\u660echar\u7684\u4f8b\u5b50\u3002<\/p>\n
fn main() { let c = 'z'; let z: char = '\u2124'; \/\/ with explicit type annotation let heart_eyed_cat = '\ud83d\ude3b'; }<\/code><\/pre>\n\u8bf7\u6ce8\u610f\uff0c<\/p>\n
\u6211\u4eec\u7528\u5355\u5f15\u53f7\u6307\u5b9a\u5b57\u7b26\u6587\u672c\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u53cc\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\u6587\u672c\u3002Rust \u7684 char \u7c7b\u578b\u5927\u5c0f\u4e3a 4 \u4e2a\u5b57\u8282\uff0c\u4ee3\u8868\u4e00\u4e2a Unicode \u6807\u91cf\u503c\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u4ee3\u8868\u7684\u4e0d\u4ec5\u4ec5\u662f ASCII\u3002\u91cd\u97f3\u5b57\u6bcd;\u4e2d\u6587\u3001\u65e5\u6587\u548c\u97e9\u6587\u5b57\u7b26;\u8868\u60c5\u7b26\u53f7;\u548c\u96f6\u5bbd\u5ea6\u7a7a\u683c\u90fd\u662f Rust \u4e2d\u7684\u6709\u6548\u5b57\u7b26\u503c\u3002Unicode \u6807\u91cf\u503c\u7684\u8303\u56f4\u4ece U+0000 \u5230 U+D7FF \u548c U+E000 \u5230 U+10FFFF \uff08\u542b\uff09\u3002\u7136\u800c\uff0c\u201c\u5b57\u7b26\u201d\u5728 Unicode \u4e2d\u5e76\u4e0d\u662f\u4e00\u4e2a\u771f\u6b63\u7684\u6982\u5ff5\uff0c\u6240\u4ee5\u4f60\u5bf9\u201c\u5b57\u7b26\u201d\u662f\u4ec0\u4e48\u76f4\u89c9\u53ef\u80fd\u4e0e Rust \u4e2d\u7684\u5b9e\u9645\u5b57\u7b26\u4e0d\u5339\u914d\u3002\u6211\u4eec\u5c06\u5728\u7b2c 8 \u7ae0\u7684\u201c\u4f7f\u7528\u5b57\u7b26\u4e32\u5b58\u50a8 UTF-8 \u7f16\u7801\u6587\u672c\u201d\u4e2d\u8be6\u7ec6\u8ba8\u8bba\u6b64\u4e3b\u9898\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"rust \u51fd\u6570_rust\u8c03\u7528c++\u5e93Rust\u6709\u4e24\u79cd\u57fa\u672c\u7684\u6d6e\u70b9\u7c7b\u578b\uff0c\u662ff32\u548cf64\uff0c\u5206\u522b\u4ee3\u886832\u7c7b\u548c64\u4f4d\u5927\u5c0f\uff0c\u9ed8\u8ba4\u6d6e\u70b9\u7c7b\u578b\u4e3af64,\u56e0\u4e3a\u5728\u73b0\u4ee3\u7684cp...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8349"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8349"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8349\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}