{"id":205800,"date":"2020-12-03T08:20:03","date_gmt":"2020-12-03T00:20:03","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=205800"},"modified":"2020-11-23T11:22:28","modified_gmt":"2020-11-23T03:22:28","slug":"how-rust-outputs","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/how-rust-outputs.html","title":{"rendered":"Rust \u5982\u4f55\u8f93\u51fa\u5230\u547d\u4ee4\u884c"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nRust \u8bed\u8a00\u662f\u4e00\u79cd\u9ad8\u6548\u3001\u53ef\u9760\u7684\u901a\u7528\u9ad8\u7ea7\u8bed\u8a00\u3002\u5176\u9ad8\u6548\u4e0d\u4ec5\u9650\u4e8e\u5f00\u53d1\u6548\u7387\uff0c\u5b83\u7684\u6267\u884c\u6548\u7387\u4e5f\u662f\u4ee4\u4eba\u79f0\u8d5e\u7684\uff0c\u662f\u4e00\u79cd\u5c11\u6709\u7684\u517c\u987e\u5f00\u53d1\u6548\u7387\u548c\u6267\u884c\u6548\u7387\u7684\u8bed\u8a00\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"
\n\u5728\u6b63\u5f0f\u5b66\u4e60 Rust \u8bed\u8a00\u4ee5\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b66\u4f1a\u600e\u6837\u8f93\u51fa\u4e00\u6bb5\u6587\u5b57\u5230\u547d\u4ee4\u884c\uff0c\u8fd9\u51e0\u4e4e\u662f\u5b66\u4e60\u6bcf\u4e00\u95e8\u8bed\u8a00\u4e4b\u524d\u5fc5\u5907\u7684\u6280\u80fd\uff0c\u56e0\u4e3a\u8f93\u51fa\u5230\u547d\u4ee4\u884c\u51e0\u4e4e\u662f\u8bed\u8a00\u5b66\u4e60\u9636\u6bb5\u7a0b\u5e8f\u8868\u8fbe\u7ed3\u679c\u7684\u552f\u4e00\u65b9\u5f0f\u3002<\/p>\n

\u5728\u4e4b\u524d\u7684 Hello, World \u7a0b\u5e8f\u4e2d\u5927\u6982\u5df2\u7ecf\u544a\u8bc9\u4e86\u5927\u5bb6\u8f93\u51fa\u5b57\u7b26\u4e32\u7684\u65b9\u5f0f\uff0c\u4f46\u5e76\u4e0d\u5168\u9762\uff0c\u5927\u5bb6\u53ef\u80fd\u5f88\u7591\u60d1\u4e3a\u4ec0\u4e48 println!( \"Hello World\") \u4e2d\u7684 println \u540e\u9762\u8fd8\u6709\u4e00\u4e2a ! \u7b26\u53f7\uff0c\u96be\u9053 Rust \u51fd\u6570\u4e4b\u540e\u90fd\u8981\u52a0\u4e00\u4e2a\u611f\u53f9\u53f7\uff1f\u663e\u7136\u5e76\u4e0d\u662f\u8fd9\u6837\u3002println \u4e0d\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u800c\u662f\u4e00\u4e2a\u5b8f\u89c4\u5219\u3002\u8fd9\u91cc\u4e0d\u9700\u8981\u66f4\u6df1\u523b\u7684\u6316\u6398\u5b8f\u89c4\u5219\u662f\u4ec0\u4e48\uff0c\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u4f1a\u4e13\u95e8\u4ecb\u7ecd\uff0c\u5e76\u4e0d\u5f71\u54cd\u63a5\u4e0b\u6765\u7684\u4e00\u6bb5\u5b66\u4e60\u3002<\/p>\n

Rust \u8f93\u51fa\u6587\u5b57\u7684\u65b9\u5f0f\u4e3b\u8981\u6709\u4e24\u79cd\uff1aprintln!() \u548c print!()\u3002\u8fd9\u4e24\u4e2a\"\u51fd\u6570\"\u90fd\u662f\u5411\u547d\u4ee4\u884c\u8f93\u51fa\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\uff0c\u533a\u522b\u4ec5\u5728\u4e8e\u524d\u8005\u4f1a\u5728\u8f93\u51fa\u7684\u6700\u540e\u9644\u52a0\u8f93\u51fa\u4e00\u4e2a\u6362\u884c\u7b26\u3002\u5f53\u7528\u8fd9\u4e24\u4e2a\"\u51fd\u6570\"\u8f93\u51fa\u4fe1\u606f\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u683c\u5f0f\u5b57\u7b26\u4e32\uff0c\u540e\u9762\u662f\u4e00\u4e32\u53ef\u53d8\u53c2\u6570\uff0c\u5bf9\u5e94\u7740\u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u7684\"\u5360\u4f4d\u7b26\"\uff0c\u8fd9\u4e00\u70b9\u4e0e C \u8bed\u8a00\u4e2d\u7684 printf \u51fd\u6570\u5f88\u76f8\u4f3c\u3002\u4f46\u662f\uff0cRust \u4e2d\u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u7684\u5360\u4f4d\u7b26\u4e0d\u662f\"% + \u5b57\u6bcd\"\u7684\u5f62\u5f0f\uff0c\u800c\u662f\u4e00\u5bf9 {}\u3002<\/p>\n

\u5b9e\u4f8b<\/strong><\/div>\n
\r\nfn main() {\r\n    let a = 12;\r\n    println!(\"a is {}\", a);\r\n}<\/pre>\n

\u4ee5\u4e0a\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\uff1a<\/p>\n

\r\na is 12 <\/pre>\n

\u5982\u679c\u6211\u60f3\u628a a \u8f93\u51fa\u4e24\u904d\uff0c\u90a3\u5c82\u4e0d\u662f\u8981\u5199\u6210\uff1a<\/p>\n

\r\nprintln!(\"a is {}, a again is {}\", a, a); <\/pre>\n

\u5176\u5b9e\u6709\u66f4\u597d\u7684\u5199\u6cd5\uff1a<\/p>\n

\r\nprintln!(\"a is {0}, a again is {0}\", a); <\/pre>\n

\u5728 {} \u4e4b\u95f4\u53ef\u4ee5\u653e\u4e00\u4e2a\u6570\u5b57\uff0c\u5b83\u5c06\u628a\u4e4b\u540e\u7684\u53ef\u53d8\u53c2\u6570\u5f53\u4f5c\u4e00\u4e2a\u6570\u7ec4\u6765\u8bbf\u95ee\uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u3002<\/p>\n

\u5982\u679c\u8981\u8f93\u51fa { \u6216 } \u600e\u4e48\u529e\u5462\uff1f\u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u901a\u8fc7 {{ \u548c }} \u5206\u522b\u8f6c\u4e49\u4ee3\u8868 { \u548c }\u3002\u4f46\u662f\u5176\u4ed6\u5e38\u7528\u8f6c\u4e49\u5b57\u7b26\u4e0e C \u8bed\u8a00\u91cc\u7684\u8f6c\u4e49\u5b57\u7b26\u4e00\u6837\uff0c\u90fd\u662f\u53cd\u659c\u6760\u5f00\u5934\u7684\u5f62\u5f0f\u3002<\/p>\n

\r\nfn main() { \r\n    println!(\"{{}}\"); \r\n} <\/pre>\n

\u4ee5\u4e0a\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\uff1a<\/p>\n

\r\n{}<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5728\u6b63\u5f0f\u5b66\u4e60 Rust \u8bed\u8a00\u4ee5\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b66\u4f1a\u600e\u6837\u8f93\u51fa\u4e00\u6bb5\u6587\u5b57\u5230\u547d\u4ee4\u884c\uff0c\u8fd9\u51e0\u4e4e\u662f\u5b66\u4e60\u6bcf\u4e00\u95e8\u8bed\u8a00\u4e4b\u524d\u5fc5\u5907\u7684\u6280\u80fd\uff0c […]<\/p>\n","protected":false},"author":321,"featured_media":205801,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-205800","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=205800"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205800\/revisions"}],"predecessor-version":[{"id":205803,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205800\/revisions\/205803"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/205801"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=205800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=205800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=205800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}