diff --git a/_layouts/zh-CN/basic.html b/_layouts/zh-CN/basic.html index 81be01e8a..d68550793 100644 --- a/_layouts/zh-CN/basic.html +++ b/_layouts/zh-CN/basic.html @@ -6,16 +6,19 @@ {{ page.title }} - + + {% for css_name in page.extra_css %} + + {% endfor %} - +
@@ -37,7 +40,7 @@

贡献

{{ content }} diff --git a/logos/forkme_zh_cn.svg b/logos/forkme_zh_cn.svg index 1d04542ce..9ecf6d71d 100644 --- a/logos/forkme_zh_cn.svg +++ b/logos/forkme_zh_cn.svg @@ -6,7 +6,7 @@ - 从GitHub上拷贝源码 + Fork 在 GitHub 上的代码 \ No newline at end of file diff --git a/zh-CN/community.md b/zh-CN/community.md index 2ff445573..cd3fa406b 100644 --- a/zh-CN/community.md +++ b/zh-CN/community.md @@ -5,48 +5,33 @@ title: Rust 社区 · Rust 程序设计语言 # Rust 社区 -The Rust programming language has many qualities, but Rust's greatest -strength is the community of people who come together to make working -in Rust a rewarding experience. - -We are committed to providing a friendly, safe and welcoming -environment for all, regardless of gender, sexual orientation, -disability, ethnicity, religion, or similar personal -characteristic. Our [code of conduct][coc] sets the standards for -behavior in all official Rust forums. - -If you feel you have been or are -being harassed or made uncomfortable by a community member, please -[contact][mod_team_email] any of the [Rust Moderation Team][mod_team] -immediately. Whether you are a regular contributor or a newcomer, we -care about making the community a safe space for you. +Rust 编程语言有很多特质,但 Rust 最伟大的力量是,我们的社区团结一心,为更好的 Rust 体验在努力。 + +我们致力于提供友好、安全和欢迎所有人的环境,无论性别,性取向,残疾,种族,宗教或类似的个人特征。我们的[行为守则][coc]为所有官方 Rust 论坛中的行为设定了标准。 + +如果您感觉到不适或者正被社区成员骚扰,请立即[联系][mod_team_email] [Rust 管理团队][mod_team]中的任何人。无论您是常规贡献者还是新来者,我们都十分关切您在社区的感受。 [coc]: https://www.rust-lang.org/conduct.html [mod_team]: https://www.rust-lang.org/team.html#Moderation [mod_team_email]: mailto:rust-mods@rust-lang.org -## Getting Started +## 入门 -The most important community resources for those new to Rust are: +对 Rust 来说,最重要的社区资源是: -- [#rust-beginners][beginners_irc], an IRC channel that - loves answering questions at any depth. -- The [Users Forum][users_forum], for discussion of all - things Rust. +- [#rust-beginners][beginners_irc],欢迎任何程度提问的 IRC 频道。 +- [用户论坛][users_forum],讨论一切有关 Rust 的内容。 -You may also find help on the question and answer site, [Stack Overflow][stack_overflow]. +您也可以在问答网站上得到帮助,例如 [Stack Overflow][stack_overflow]。 [stack_overflow]: https://stackoverflow.com/questions/tagged/rust ## 新闻 -[This Week in Rust][twir] collects the latest news, upcoming events -and a week-by-week account of changes in the Rust language and -libraries. [The Rust Blog][rust_blog] is where the Rust team makes -announcements about major developments. And nearly everything happening in -Rust is discussed on the unofficial subreddit, [/r/rust][reddit]. +[本周 Rust][twir] 收集最新的消息、即将举办的活动,以及每周一次的有关 Rust 语言及库的变动记事。[Rust 博客][rust_blog] 是 Rust 团队公告主要发展的地方。 +最后,几乎所有发生在 Rust 的变化都在非官方的 subreddit、[/r/rust][reddit] 上讨论。 -您也可以关注我们的[推特][twitter]账号或者是[新浪微博][weibo]。 +您还可以关注我们的 [Twitter][twitter] 账号或[新浪微博][weibo]。 [twir]: https://this-week-in-rust.org/ [rust_blog]: http://blog.rust-lang.org/ @@ -57,25 +42,22 @@ Rust is discussed on the unofficial subreddit, [/r/rust][reddit]. ## IRC 频道 -Rustaceans maintain a number of friendly, high-traffic [IRC] channels on Mozilla's IRC network, irc.mozilla.org. +Rustaceans 在 Mozilla 的 IRC 网络 irc.mozilla.org 上维护了一些友好、高流量的 [IRC] 频道。 -The [#rust][rust_irc] channel is a venue for general -discussion about Rust, and a good place to ask for help. You'll find -people willing to answer any questions about Rust, and -responses are typically fast. +[#rust][rust_irc] 频道是讨论 Rust 的一般场所,并且是寻求帮助的好地方。你能找到愿意回答 Rust 有关的任何问题的人,响应通常很快。 -Rust's developers coordinate in [#rust-internals][internals_irc]. It is for real-time discussion about hacking on Rust itself. It is also the channel to ask questions about contributing to Rust. +Rust 开发者的协调位于 [#rust-internals][internals_irc]。此频道中的实时讨论有关调整 Rust 本身,包括提出 Rust 本身的问题。 ### 主要频道 -- [#rust][rust_irc] 关于 Rust 的所有内容 -- [#rust-beginners][beginners_irc] Rust 语言的初学者频道, lower traffic than #rust -- [#rust-internals][internals_irc] is for discussion of other Rust implementation topics -- [#rustc][rustc_irc] is the home of the [compiler team][compiler_team] -- [#rust-libs][libs_irc] is the home of the [libraries team][library_team] -- [#rust-tools][tools_irc] is the home of the [tools and infrastructure team][tool_team] -- [#rust-lang][lang_irc] is the home of the [language team][language_team] -- [#rust-community][community_irc] is the home of the [community team][community_team] +- [#rust][rust_irc] 谈论有关 Rust 的所有内容 +- [#rust-beginners][beginners_irc] 是 Rust 语言初学者的频道,流量比 #rust 少一些 +- [#rust-internals][internals_irc] 讨论其他 Rust 实现的主题 +- [#rustc][rustc_irc]是[编译器团队][compiler_team]的家 +- [#rust-libs][libs_irc]是[库团队][library_team]的家 +- [#rust-tools][tools_irc]是[工具和基础设施][tool_team]的家 +- [#rust-lang][lang_irc]是[语言团队][language_team]的家 +- [#rust-community][community_irc]是[社区团队][community_team]的家 ### 国际频道 @@ -88,16 +70,17 @@ Rust's developers coordinate in [#rust-internals][internals_irc]. It is for real ### 专题频道 -- [#cargo][cargo_irc] is for discussion of Cargo, Rust's package manager -- [#rust-bots][bots_irc] notifications about Rust from a selection of bots -- [#rust-docs][docs_irc] is the home of the unoffical documentation team -- [#rust-crypto][crypto_irc] is for discussion of cryptography in Rust -- [#rust-gamedev][gamedev_irc] is for people doing game development in Rust -- [#rust-networking][networking_irc] is for people doing computer networking and development in Rust -- [#rust-offtopic][offtopic_irc] is for general chit-chat amongst Rustaceans -- [#rust-osdev][osdev_irc] is for people doing OS development in Rust -- [#rust-webdev][webdev_irc] is for people doing web development in Rust -- [#servo][servo_irc] is for discussion of Servo, the browser engine written in Rust +- [#cargo][cargo_irc] 讨论 Rust 的包管理器 —— Cargo +- [#rust-bots][bots_irc] 是一系列机器人通知 Rust 的相关事情的地方 +- [#rust-docs][docs_irc] 是非官方的文档团队的家 +- [#rust-crypto][crypto_irc] 讨论 Rust 中的密码学部分 +- [#rust-embedded][embedded_irc] 有关使用 Rust 制作嵌入式软件 +- [#rust-gamedev][gamedev_irc] 有关使用 Rust 开发游戏 +- [#rust-networking][networking_irc] 有关使用 Rust 进行计算机网络相关开发 +- [#rust-offtopic][offtopic_irc] 是供人们在 Rustaceans 上天南海北地闲聊 +- [#rust-osdev][osdev_irc] 有关使用 Rust 开发操作系统 +- [#rust-webdev][webdev_irc] 有关使用 Rust 做 Web 开发 +- [#servo][servo_irc] 用于讨论 Servo,它是使用 Rust 编写的一个浏览器引擎 [IRC]: https://en.wikipedia.org/wiki/Internet_Relay_Chat [beginners_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-beginners @@ -109,6 +92,7 @@ Rust's developers coordinate in [#rust-internals][internals_irc]. It is for real [crypto_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-crypto [de_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-de [es_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-es +[embedded_irc]: https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-embedded [fr_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-fr [gamedev_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-gamedev [internals_irc]: https://client00.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals @@ -127,106 +111,78 @@ Rust's developers coordinate in [#rust-internals][internals_irc]. It is for real ## 论坛 -We have two forums for asynchronous discussion: +我们有两个异步讨论论坛: -- The [Users Forum][users_forum], a space for asking questions, posting code - snippets, talking about Rust projects, and so on. +- [用户论坛][users_forum],提出疑问、张贴代码片段、谈论 Rust 项目的空间。 -- The [Internals Forum][internals_forum], a space dedicated to design and - implementation discussion about Rust itself (which includes Cargo, the - standard library, and other core bits of infrastructure). +- [内部论坛][internals_forum],专用于 Rust 本身的设计和实现的讨论,这包括 Cargo、标准库和其他基础架构的核心。 [users_forum]: https://users.rust-lang.org/ [internals_forum]: https://internals.rust-lang.org/ -## User Groups and Meetups +## 用户群组和会议 -There are more than 50 [Rust User Groups][user_group] worldwide in over 20 -countries totaling over 7,000 members. Rustaceans meet periodically in Rust User -Groups. Its a great introduction to the community and a great way to learn and -socialize with other people with a similar interest. Meetings are -usually held monthly and very informal. Meetings are open to everyone. +这里有超过 35 个国家或地区的 90 个 [Rust 用户群组][user_group]。Rustaceans 不时在 Rust 用户群组中碰面。 +这是极好的参与社区的方式,并也是一个不错的学习方式,与兴趣相似的其他人交流。 +会议通常每月举行,不是那么正式、严肃。会议面向所有人开放。 -There is a global [calendar][calendar] for keeping up with Rust events. -Contact the [community team][community_team] to add your own. +有一个全局[日历][calendar]可以持续关注 Rust 的事件与活动。 +联系[社区团队][community_team]添加你的内容。 [user_group]: ./user-groups.html [calendar]: https://www.google.com/calendar/embed?src=apd9vmbc22egenmtu5l6c5jbfc@group.calendar.google.com ## Rust 团队 -Rust has a community-driven development process where most decisions are made -through open discussion and consensus, under the stewardship of various -[teams][teams]: +Rust 有一个社区驱动的开发过程,大多数决策都是通过公开的讨论和共识,在各方面[团队][teams]的指导下做出: -* The [Core Team][core_team] is responsible for steering the design and -development process, overseeing the introduction of new features, and ultimately -making decisions for which there is no consensus (this happens rarely). +* [核心团队][core_team]是负责指导设计和发展流程,监督新特性的引入,以及最终做出无法达成共识的决定(这很少发生)。 -* The [Language Design Team][language_team] is responsible for the - design of new language features. +* [语言设计团队][language_team]负责设计新的语言特性。 -* The [Library Team][library_team] is responsible for the Rust standard -library, rust-lang crates, and conventions. +* [库团队][library_team]负责 Rust 标准库、rust-lang 包装箱,及公约。 -* The [Compiler Team][compiler_team] is responsible for compiler internals and -optimizations. +* [编译器团队][compiler_team]负责编译器内部和优化。 -* The [Tooling and Infrastructure Team][tool_team] is responsible for official -tools like [Cargo], [rustup], and [rustfmt], as well as the CI Infrastructure for the -project. +* [工具团队][tool_team]负责官方工具,例如 [Cargo]、[rustup] 和 [rustfmt]。 + +* [基础设施团队][infra_team]负责支持项目本身的工具:CI、发布生成、机器人、指标。 [Cargo]: https://crates.io [rustup]: https://www.rustup.rs [rustfmt]: https://github.com/rust-lang-nursery/rustfmt -* The [Community Team][community_team] is responsible for coordinating events, -outreach, commercial users, teaching materials, and exposure. They can also -direct inquiries to the correct parties when its not clear who to contact -about something Rusty. - -* The [Moderation Team][mod_team] is responsible for helping to uphold the -[code of conduct][coc]. - -* The [Documentation Team][doc_team] is responsible for ensuring Rust has - fantastic documentation. - -In addition to the official team rosters, most teams also have a larger set -of reviewers who are knowledgeable about the area and can sign off on -code. If you're interested in getting involved in one of these teams, -feel free to reach out to the team leader or any other member, who can -help get you started. - -[teams]: https://www.rust-lang.org/team.html -[core_team]: https://www.rust-lang.org/team.html#Core -[language_team]: https://www.rust-lang.org/team.html#Language-design -[library_team]: https://www.rust-lang.org/team.html#Library -[compiler_team]: https://www.rust-lang.org/team.html#Compiler -[tool_team]: https://www.rust-lang.org/team.html#Tooling-and-infrastructure -[community_team]: https://www.rust-lang.org/team.html#Community -[mod_team]: https://www.rust-lang.org/team.html#Moderation -[doc_team]: https://www.rust-lang.org/en-US/team.html#Documentation-team +* [社区团队][community_team]负责协调活动、推广、商业用户、教材和曝光。他们也可以就联络 Rust 当事人进行协调。 + +* [管理团队][mod_team]负责维护[行为守则][coc]。 + +* [文档团队][doc_team]负责确保 Rust 有出色的文档。 + +除了上述官方团队名册,大多数团队也都有更大的一套了解该领域知识并且可以签发代码的审稿人。 +如果您有兴趣参与上述团队,随时与团队领导或其中的其他成员联系,他可以帮助你入门。 + +[teams]: team.html +[core_team]: team.html#Core-team +[language_team]: team.html#Language-design-team +[library_team]: team.html#Library-team +[compiler_team]: team.html#Compiler-team +[tool_team]: team.html#Tools-team +[community_team]: team.html#Community-team +[mod_team]: team.html#Moderation-team +[doc_team]: team.html#Documentation-team +[infra_team]: team.html#Infrastructure-team ## Rust 开发 -Rust has had over [1,200 different contributors][authors], a number that grows -every single week. [We'd love for you to join that list][contribute]! +Rust 有超过[1,200名独立贡献者][authors],这个数字每周还都在增长。[我们欢迎你加入到此行列中][contribute]! -As mentioned above, the [Rust Internals Forum][internals_forum] is dedicated to -discussing the design and implementation of Rust. A lot of discussion also -happens on GitHub: +如上所述,[Rust 内部论坛][internals_forum]致力于讨论 Rust 的设计和实现。还有很多讨论发生在 GitHub 上: -- The [main repository][github] and [issue tracker][issue_tracking] are the - front lines of the implementation work. Our reviewers strive to be friendly - and to help mentor newcomers, so don't hesitate to open a pull request! +- [主代码库][github]和[问题跟踪器][issue_tracking]是最前沿的工作阵地。我们的审阅者力求友善引导并帮助新手,所以无需犹豫,打开拉取请求! -- The [RFC repo][rfcs] tracks our Request for Comment process, the main pathway - through which the Rust community and the teams reach consensus on new - features proposed for the language and official libraries and tools. +- [RFC 代码库][rfcs]跟踪我们的请求评论流程,Rust 社区和团队主要通过它就为语言、官方库和工具提出的新功能特性达成共识。 -Roughly weekly, the Rust teams produce [team reports][team_reports] tracking -team business, including the progression of proposals through the RFC and -implementation process. +大约每周,Rust 团队会制作一份[团队报告][team_reports]跟踪团队事务,包括 RFC 实现流程的提案进展。 [authors]: https://github.com/rust-lang/rust/blob/88397e092e01b6043b6f65772710dfe0e59056c5/AUTHORS.txt [contribute]: contribute.html diff --git a/zh-CN/conduct.md b/zh-CN/conduct.md index d94f23f68..4a84e6da0 100644 --- a/zh-CN/conduct.md +++ b/zh-CN/conduct.md @@ -1,13 +1,13 @@ --- layout: zh-CN/default -title: The Rust Code of Conduct · Rust 程序设计语言 +title: Rust 行为守则 · Rust 程序设计语言 --- -# The Rust Code of Conduct +# Rust 行为守则 -## Conduct +## 行为举止 -**Contact**: [rust-mods@rust-lang.org](mailto:rust-mods@rust-lang.org) +**联系**:[rust-mods@rust-lang.org](mailto:rust-mods@rust-lang.org) * We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic. * On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all. @@ -18,10 +18,10 @@ title: The Rust Code of Conduct · Rust 程序设计语言 * Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the [Rust moderation team](/team.html#Moderation) immediately. Whether you're a regular contributor or a newcomer, we care about making this community a safe place for you and we've got your back. * Likewise any spamming, trolling, flaming, baiting or other attention-stealing behaviour is not welcome. -## Moderation +## 管理 -These are the policies for upholding our community's standards of conduct. If you feel that a thread needs moderation, please contact the [Rust moderation team](/team.html#Moderation). +These are the policies for upholding our community's standards of conduct. 如果你认为某个主题需要被处理,请联系 [Rust 管理团队](/team.html#Moderation)。 1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.) 2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed. diff --git a/zh-CN/contribute-bugs.md b/zh-CN/contribute-bugs.md index f856b7719..ba764ffff 100644 --- a/zh-CN/contribute-bugs.md +++ b/zh-CN/contribute-bugs.md @@ -1,46 +1,30 @@ --- layout: zh-CN/default -title: Contributing to Rust — finding, triaging and fixing issues · Rust 程序设计语言 +title: 为 Rust 出力 — 找出、分类和修复问题 · Rust 程序设计语言 --- -# Contributing to Rust — finding, triaging and fixing issues +# 为 Rust 出力 — 找出、分类和修复问题 -The day-to-day maintenance of the project revolves around Rust's -[issue tracker] and [pull requests][PR], and more help is always -needed. The most basic way to get started contributing to Rust is to -look for the [E-easy] or [E-mentor] labels. These are meant to be -approachable for new Rust programmers. +Rust 项目的的日常维护工作是围绕着[问题跟踪器][issue tracker]和[拉取请求][PR],并且始终需要更多的贡献。 +开始为 Rust 出力的最简单方式是寻找标有 [E-easy] 或 [E-mentor] 标签的问题。 +它们最适合新手 Rust 程序员。 -On `E-mentor` issues an experienced Rust developer has volunteered in -the comments to mentor you through solving the issue and [submitting -the fix via GitHub pull request][pull]. Contact them about the issue, -on the issue tracker by [@mentioning] their name in a comment, on IRC, -or through email. Note that Rust developers get a lot of notifications -and it is easy to miss some; don't hesitate to hunt them down by -whatever means necessary! +在标有 `E-mentor` 的问题上会有一名经验丰富的 Rust 开发人员来自愿帮助你解决该问题和[提交 GitHub 拉取请求][pull]来修复它。 +在评论、IRC 中用 [@mentioning] 来联系他们(也可通过电子邮件)。 +温馨提醒,Rust 开发人员经常收到大量的通知,所以有时可能错过某些; +不要犹豫!如果你认为他没有注意到你。 -Other projects in Rust maintain similar entry-level tasks, including -the web browser [Servo], the HTTP library [hyper], the -source-formatter [rustfmt], the Unix library bindings [nix], -and the lint collection [clippy]. +Rust 的其他项目也有其他类似的入门级任务,包括网页浏览器 [Servo],HTTP 库 [hyper],源代码格式化器 [rustfmt],Unix 库绑定 [nix],以及 lint 集 [clippy]。 -While Rust has an [extensive test suite][test] there is always more to -test. The [E-needstest] label indicates issues that are thought to be -fixed but don't have tests. Writing test cases is a great way to -understand a new project and get started contributing. +虽然 Rust 有一个[广泛的测试套件][test],但测试总是不嫌多的嘛。 +[E-needstest] 标签指出了被认为已修复但尚未测试的问题。编写测试用例也是很好的一个了解新项目并开始贡献的方法。 -Rust is always in need of people to [triage] issues: reproduce bugs, -minimize test cases, apply labels, close resolved issues. Note that -you'll need elevated GitHub permissions to apply labels, but this is -easy to obtain for somebody with a bit of experience in the -project. Ask a [team member][team]. +Rust 始终需要人们来[分流][triage]问题:重现 bug, +最小化的测试用例,应用标签,关闭已解决的问题。 +请注意,您需要被提升的 GitHub 权限才能应用标签, +不过卓有经验的人很容易得到它,相关事宜请联系[团队成员][team]。 -Once you've found your way around the project and have created a few -pull requests in a particular area, consider reviewing others' pull -requests: good reviewership is a rare skill and always appreciated. No -prior permission is needed — just start constructively and politely -commenting on pull requests that interest you. If you want training -on conducting good code reviews [read this guide][reviews]. +在您找到自己的方式为项目出力并创建一些拉取请求后,可以考虑审阅其他人的拉取请求:良好的审阅是一个不可多得的技能。无需事先批准 — 只需开始礼貌并有建设性地在您感兴趣的拉取请求中评论。如果您想在代码审核的基础上有效分流,[阅读这份指南][reviews]。

-How can I try Rust easily? +怎样轻松地尝试 Rust?

-The easiest way to try Rust is through the [playpen](https://play.rust-lang.org/), an online app for writing and running Rust code. If you want to try Rust on your system, [install it](https://www.rust-lang.org/install.html) and go through the [Guessing Game](https://doc.rust-lang.org/stable/book/guessing-game.html) tutorial in the book. +[playpen](https://play.rust-lang.org/) 是尝试 Rust 的最简单方法,它是一个可编写和运行 Rust 代码的在线应用。如果您想在您的系统上尝试 Rust,[安装](https://www.rust-lang.org/install.html)并尝试[猜谜游戏](https://doc.rust-lang.org/stable/book/guessing-game.html)教程。

-How do I get help with Rust issues? +如何就 Rust 问题取得帮助?

-There are several ways. You can: +那有很多种方式。您可以尝试: -- Post in [users.rust-lang.org](https://users.rust-lang.org/), the official Rust users forum -- Ask in the official [Rust IRC channel](https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) (#rust on irc.mozilla.org) -- Ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/rust) with the "rust" tag -- Post in [/r/rust](https://www.reddit.com/r/rust), the unofficial Rust subreddit +- 在 [users.rust-lang.org](https://users.rust-lang.org/) 发帖,这是官方的 Rust 用户论坛 +- 在官方的 [Rust IRC 频道](https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) 询问 (irc.mozilla.org 上的 #rust) +- 在 [Stack Overflow](https://stackoverflow.com/questions/tagged/rust) 询问,加上 "rust" 标签 +- 在 [/r/rust](https://www.reddit.com/r/rust) 发帖,这是非官方的 Rust 板块

-Why has Rust changed so much over time? +为什么 Rust 随时间推移在大幅变化?

-Rust started with a goal of creating a safe but usable systems programming language. In pursuit of this goal it explored a lot of ideas, some of which it kept (lifetimes, traits) while others were discarded (the typestate system, green threading). Also, in the run up to 1.0 a lot of the standard library was rewritten as early designs were updated to best use Rust's features and provide quality, consistent cross-platform APIs. Now that Rust has reached 1.0, the language is guaranteed to be "stable"; and while it may continue to evolve, code which works on current Rust should continue to work on future releases. +Rust 起步的目标是创建一个安全且合用的系统编程语言。为了追求这个目标,它探索了很多想法,其中一些(生命周期、traits)被保留,而其他则被丢弃(类型体系系统、绿色线程)。 Also, in the run up to 1.0 a lot of the standard library was rewritten as early designs were updated to best use Rust's features and provide quality, consistent cross-platform APIs. 现在的 Rust 已达到了 1.0,语言保证为“稳定”(stable);虽然它可能继续演变,但对于目前的 Rust 来说,代码在未来的发行版本上能继续工作。

-How does Rust language versioning work? +Rust 语言的版本控制是怎样的?

-Rust's language versioning follows [SemVer](http://semver.org/), with backwards incompatible changes of stable APIs only allowed in minor versions if those changes fix compiler bugs, patch safety holes, or change dispatch or type inference to require additional annotation. More detailed guidelines for minor version changes are available as approved RFCs for both the [language](https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md) and [standard library](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md). +Rust 的语言版本遵循 [SemVer](http://semver.org/),如果更改修复了编译器错误、补丁安全漏洞,或更改调度或类型推断需要附加注明,则稳定 API 的向后不兼容更改允许在次要版本中出现。次要版本更改的更详细指南可以在[语言](https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md)和[标准库](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md)的已批准 RFC 中找到。 -Rust maintains three "release channels": stable, beta, and nightly. Stable and beta are updated every six weeks, with the current nightly becoming the new beta, and the current beta becoming the new stable. Language and standard library features marked unstable or hidden behind feature gates may only be used on the nightly release channel. New features land as unstable, and are "ungated" once approved by the core team and relevant subteams. This approach allows for experimentation while providing strong backwards-compatibility guarantees for the stable channel. +Rust 维护三个“发行频道”:稳定版(stable)、测试版(beta)和每夜版(nightly)。稳定版和测试版每六周更新一次,而在那时的每夜版会变为新的测试版,测试版变为新的稳定版。语言和标准库特性 marked unstable or hidden behind feature gates may only be used on the nightly release channel. New features land as unstable, and are "ungated" once approved by the core team and relevant subteams. 这种方法允许实验性变更,并同时为稳定频道提供强有力的向后兼容保证。 -For additional details, read the Rust blog post ["Stability as a Deliverable."](http://blog.rust-lang.org/2014/10/30/Stability.html) +就相关的其他详细信息,请阅读 Rust 博客["Stability as a Deliverable."](http://blog.rust-lang.org/2014/10/30/Stability.html)

-Can I use unstable features on the beta or stable channel? +我可以在 Beta 或稳定频道上使用不稳定的功能吗?

-No, you cannot. Rust works hard to provide strong guarantees about the stability of the features provided on the beta and stable channels. When something is unstable, it means that we can't provide those guarantees for it yet, and don't want people relying on it staying the same. This gives us the opportunity to try changes in the wild on the nightly release channel, while still maintaining strong guarantees for people seeking stability. +并不能。Rust works hard to provide strong guarantees about the stability of the features provided on the beta and stable channels. When something is unstable, it means that we can't provide those guarantees for it yet, and don't want people relying on it staying the same. This gives us the opportunity to try changes in the wild on the nightly release channel, while still maintaining strong guarantees for people seeking stability. Things stabilize all the time, and the beta and stable channels update every six weeks, with occasional fixes accepted into beta at other times. If you're waiting for a feature to be available without using the nightly release channel, you can locate its tracking issue by checking the [`B-unstable`](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+tracking+label%3AB-unstable) tag on the issue tracker.

-What are "Feature Gates"? +什么是“特性门控”(Feature Gates)?

-"Feature gates" are the mechanism Rust uses to stabilize features of the compiler, language, and standard library. A feature that is "gated" is accessible only on the nightly release channel, and then only when it has been explicitly enabled through `#[feature]` attributes or the `-Z unstable-options` command line argument. When a feature is stabilized it becomes available on the stable release channel, and does not need to be explicitly enabled. At that point the feature is considered "ungated". Feature gates allow developers to test experimental features while they are under development, before they are available in the stable language. +“特性门控”(Feature Gates)是 Rust 用来稳定编译器、语言和标准库特性的机制。 A feature that is "gated" is accessible only on the nightly release channel, and then only when it has been explicitly enabled through `#[feature]` attributes or the `-Z unstable-options` command line argument. When a feature is stabilized it becomes available on the stable release channel, and does not need to be explicitly enabled. At that point the feature is considered "ungated". Feature gates allow developers to test experimental features while they are under development, before they are available in the stable language.

-Why a dual MIT/ASL2 License? +为什么采用 MIT/ASL2 双许可证?

-The Apache license includes important protection against patent aggression, but it is not compatible with the GPL, version 2. To avoid problems using Rust with GPL2, it is alternately MIT licensed. +Apache 许可证包含对专利侵权的重要保护,但它与 GPL 第二版不兼容。为避免 Rust 使用 GPL2 会遇到的问题,因而同时采用 MIT 许可证。

-Why a BSD-style permissive license rather than MPL or tri-license? +为什么是 BSD 风格的许可证,而不是 MPL 或三个许可证?

-This is partly due to preference of the original developer (Graydon), and partly due to the fact that languages tend to have a wider audience and more diverse set of possible embeddings and end-uses than products such as web browsers. We'd like to appeal to as many of those potential contributors as possible. +这一部分是由于原始开发者(Graydon)的偏好,另一部分原因在于,语言倾向于拥有更广泛的受众群体,以及将其更多样的嵌入和提供到终端,例如网页浏览器。。我们希望呼吁尽可能多地潜在贡献者。 -

Performance

+

性能

-How fast is Rust? +Rust 有多快?

-Fast! Rust is already competitive with idiomatic C and C++ in a number of benchmarks (like the [Benchmarks Game](https://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=rust&lang2=gpp) and [others](https://github.com/kostya/benchmarks)). +飞快!Rust 在一些基准测试中(例如 [Benchmarks Game](https://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=rust&lang2=gpp)、[等等](https://github.com/kostya/benchmarks))已经有与惯用的 C 和 C++ 竞争的能力。 -Like C++, Rust takes [zero-cost abstractions](http://blog.rust-lang.org/2015/05/11/traits.html) as one of its core principles: none of Rust's abstractions impose a global performance penalty, nor is there overhead from any runtime system. +与 C++ 类似,Rust 采用[零成本抽象](http://blog.rust-lang.org/2015/05/11/traits.html)作为其核心原则之一:Rust 的抽象都没有施加全局性能损失,也不会有任何运行时系统的开销。 -Given that Rust is built on LLVM and strives to resemble Clang from LLVM's perspective, any LLVM performance improvements also help Rust. In the long run, the richer information in Rust's type system should also enable optimizations that are difficult or impossible for C/C++ code. +鉴于 Rust 建立在 LLVM 上,以及力求从 LLVM 的角度来看 C 语言,任何 LLVM 的性能改进也都有助于 Rust。从长远来看,Rust 的类型系统中更丰富的信息也应该能够实现对于 C / C++ 代码来说困难或不可能的优化。

-Is Rust garbage collected? +Rust 会垃圾收集吗?

-No. One of Rust's key innovations is guaranteeing memory safety (no segfaults) *without* requiring garbage collection. +不。Rust 的重要创新之一就是保证内存安全(无 segfaults),*无需*垃圾收集。 -By avoiding GC, Rust can offer numerous benefits: predictable cleanup of resources, lower overhead for memory management, and essentially no runtime system. All of these traits make Rust lean and easy to embed into arbitrary contexts, and make it much easier to [integrate Rust code with languages that have a GC](http://calculist.org/blog/2015/12/23/neon-node-rust/). +通过避免垃圾收集(GC),Rust 可以提供许多益处:可预测的资源清理,降低内存管理开销,基本上没有运行时系统。这些特征使 Rust 很容易嵌入到任意上下文,并使其更容易[集成 Rust 代码到有 GC 的语言](http://calculist.org/blog/2015/12/23/neon-node-rust/)。 -Rust avoids the need for GC through its system of ownership and borrowing, but that same system helps with a host of other problems, including -[resource management in general](http://blog.skylight.io/rust-means-never-having-to-close-a-socket/) and [concurrency](http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html). +Rust 通过其所有权和借用(borrowing)系统避免了垃圾收集的需求,而同一系统也有助于解决许多其他问题,包括 +[一般的资源管理](http://blog.skylight.io/rust-means-never-having-to-close-a-socket/)和[并发](http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html)。 -For when single ownership does not suffice, Rust programs rely on the standard reference-counting smart pointer type, [`Rc`](https://doc.rust-lang.org/std/rc/struct.Rc.html), and its thread-safe counterpart, [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html), instead of GC. +如果单一的所有权不够,Rust 程序依赖标准的引用计数智能指针类型,[`Rc`](https://doc.rust-lang.org/std/rc/struct.Rc.html),及其线程安全版的[`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html),而不是 GC。 -We are however investigating *optional* garbage collection as a future -extension. The goal is to enable smooth integration with -garbage-collected runtimes, such as those offered by the +不过,我们也在调查*可选*的垃圾收集作为一项未来扩展。 +其目标旨在顺利与有垃圾收集的运行时整合, +例如由 [Spidermonkey](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey) -and [V8](https://developers.google.com/v8/?hl=en) JavaScript engines. -Finally, some people have investigated implementing -[pure Rust garbage collectors](https://manishearth.github.io/blog/2015/09/01/designing-a-gc-in-rust/) -without compiler support. +和 [V8](https://developers.google.com/v8/?hl=en) JavaScript 引擎所提供的那些。 +最后,有人已调研了无编译器支持实现的 +[纯 Rust 垃圾收集器](https://manishearth.github.io/blog/2015/09/01/designing-a-gc-in-rust/) +。

-Why is my program slow? +为什么我的程序很慢?

-The Rust compiler doesn't compile with optimizations unless asked to, [as optimizations slow down compilation and are usually undesirable during development](https://users.rust-lang.org/t/why-does-cargo-build-not-optimise-by-default/4150/3). +如非要求,Rust 编译器不会优化编译,[因为优化会编译速度,且在开发过程中通常是不合需要](https://users.rust-lang.org/t/why-does-cargo-build-not-optimise-by-default/4150/3)。 -If you compile with `cargo`, use the `--release` flag. If you compile with `rustc` directly, use the `-O` flag. Either of these will turn on optimizations. +如果您使用 `cargo` 编译,请使用 `--release` 标志。如果您直接使用 `rustc`,使用 `-O` 标志。两者都将优化编译。

-Rust compilation seems slow. Why is that? +Rust 编译似乎很慢。这是为什么?

-Code translation and optimizations. Rust provides high level abstractions that compile down into efficient machine code, and those translations take time to run, especially when optimizing. +代码转换和优化。Rust提供了高级抽象,它可以编译成高效的机器代码,而这些翻译需要时间来运行,特别是优化。 -But Rust's compilation time is not as bad as it may seem, and there is reason to believe it will improve. When comparing projects of similar size between C++ and Rust, compilation time of the entire project is generally believed to be comparable. The common perception that Rust compilation is slow is in large part due to the differences in the *compilation model* between C++ and Rust: C++'s compilation unit is the file, while Rust's is the crate, composed of many files. Thus, during development, modifying a single C++ file can result in much less recompilation than in Rust. There is a major effort underway to refactor the compiler to introduce [incremental compilation](https://github.com/rust-lang/rfcs/blob/master/text/1298-incremental-compilation.md), which will provide Rust the compile time benefits of C++'s model. +但 Rust 的编译时间并不像看起来那么糟糕,并有理由相信会有所改善。当比较 C++ 与 Rust 的类似大小的项目时,整个项目的编译时间一般被认为是可比的。Rust 编译缓慢的一般认识很大程度上是由于 C++ 与 Rust 的*编译模型*的差异:C++ 的编译单元是文件,而 Rust 则是包装箱,它由很多文件组成。因此,在开发过程中,修改单个 C++ 文件导致的重新编译比 Rust 更少。正在进行的重大工作将重构编译器来引入[增量编译](https://github.com/rust-lang/rfcs/blob/master/text/1298-incremental-compilation.md),这将使 Rust 的编译时间变得比 C++ 的模型更有优势。 -Aside from the compilation model, there are several other aspects of Rust's language design and compiler implementation that affect compile-time performance. +除了编译模型外,Rust 的语言设计和编译器实现的其他几个方面也影响了编译时性能。 -First, Rust has a moderately-complex type system, and must spend a non-negligible amount of compile time enforcing the constraints that make Rust safe at runtime. +首先,Rust 有中等复杂类型的系统,并且必须花费不可忽略的编译时间来强制在运行时使 Rust 安全的约束。 -Secondly, the Rust compiler suffers from long-standing technical debt, and notably generates poor-quality LLVM IR which LLVM must spend time "fixing". There is hope that future [MIR-based](https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md) optimization and translation passes will ease the burden the Rust compiler places on LLVM. +其次,Rust 编译器遭受着长期的技术债务,特别是生成质量差的LLVM IR,而LLVM必须花时间“修复”。这有希望在未来[基于MIR](https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md)优化和转换传递来减轻 Rust 编译器在 LLVM 上的负担。 -Thirdly, Rust's use of LLVM for code generation is a double-edged sword: while it enables Rust to have world-class runtime performance, LLVM is a large framework that is not focused on compile-time performance, particularly when working with poor-quality inputs. +第三,Rust 使用的 LLVM 代码生成是一把双刃剑:虽然它能够使 Rust 具有世界一流的运行时性能,但 LLVM 是一个不重视编译时性能的大型框架,特别是在使用较差输入质量时。 -Finally, while Rust's preferred strategy of monomorphising generics (ala C++) produces fast code, it demands that significantly more code be generated than other translation strategies. Rust programmers can use trait objects to trade away this code bloat by using dynamic dispatch instead. +最后,虽然 Rust 的单性泛型(ala C ++)的首选策略产生快速代码,但它需要比其他翻译策略产生更多的代码。Rust 程序员可以使用 trait 对象通过动态调度来抵消这个代码膨胀。

-Why are Rust's HashMaps slow? +为什么 Rust 的 HashMap 很慢?

-By default, Rust's [`HashMap`][HashMap] uses the [SipHash](https://131002.net/siphash/) hashing algorithm, which is designed to prevent [hash table collision attacks](http://programmingisterrible.com/post/40620375793/hash-table-denial-of-service-attacks-revisited) while providing [reasonable performance on a variety of workloads](https://www.reddit.com/r/rust/comments/3hw9zf/rust_hasher_comparisons/cub4oh6). +默认情况下,Rust 的 [`HashMap`][HashMap] 使用 [SipHash](https://131002.net/siphash/) 哈希算法,which is designed to prevent [hash table collision attacks](http://programmingisterrible.com/post/40620375793/hash-table-denial-of-service-attacks-revisited) while providing [reasonable performance on a variety of workloads](https://www.reddit.com/r/rust/comments/3hw9zf/rust_hasher_comparisons/cub4oh6). While SipHash [demonstrates competitive performance](http://cglab.ca/%7Eabeinges/blah/hash-rs/) in many cases, one case where it is notably slower than other hashing algorithms is with short keys, such as integers. This is why Rust programmers often observe slow performance with [`HashMap`][HashMap]. The [FNV hasher](https://crates.io/crates/fnv) is frequently recommended for these cases, but be aware that it does not have the same collision-resistance properties as SipHash.

-Why is there no integrated benchmarking infrastructure? +为什么没有集成的基准测试基础设施?

-There is, but it's only available on the nightly release channel. We ultimately plan to build a pluggable system for integrated benchmarks, but in the meantime, the current system is [considered unstable](https://github.com/rust-lang/rust/issues/29553). +有,但它只在夜间发行频道上可用。我们最终计划为集成的基准建立一个可插拔系统,但同时,目前的系统[被认为是不稳定的](https://github.com/rust-lang/rust/issues/29553)。

-Does Rust do tail-call optimization? +Rust 是否做尾呼优化?

Not generally, no. Tail-call optimization may be done in [limited circumstances](http://llvm.org/docs/CodeGenerator.html#sibling-call-optimization), but is [not guaranteed](https://mail.mozilla.org/pipermail/rust-dev/2013-April/003557.html). As the feature has always been desired, Rust has a keyword (`become`) reserved, though it is not clear yet whether it is technically possible, nor whether it will be implemented. There was a [proposed extension](https://github.com/rust-lang/rfcs/pull/81) that would allow tail-call elimination in certain contexts, but it is currently postponed.

-Does Rust have a runtime? +Rust 有运行时吗?

Not in the typical sense used by languages such as Java, but parts of the Rust standard library can be considered a "runtime", providing a heap, backtraces, unwinding, and stack guards. There is a [small amount of initialization code](https://github.com/rust-lang/rust/blob/33916307780495fe311fe9c080b330d266f35bfb/src/libstd/rt.rs#L43) that runs before the user's `main` function. The Rust standard library additionally links to the C standard library, which does similar [runtime initialization](http://www.embecosm.com/appnotes/ean9/html/ch05s02.html). Rust code can be compiled without the standard library, in which case the runtime is roughly equivalent to C's. -

Syntax

+

语法

Why curly braces? Why can't Rust's syntax be like Haskell's or Python's? @@ -273,7 +274,7 @@ Rust's overall design preference is for limiting the size of the *language* whil This design choice of using Rust's macro facilities to initialize collections will likely be extended generically to other collections in the future, enabling simple initialization of not only [`HashMap`][HashMap] and [`Vec`][Vec], but also other collection types such as [`BTreeMap`][BTreeMap]. In the meantime, if you want a more convenient syntax for initializing collections, you can [create your own macro](https://stackoverflow.com/questions/27582739/how-do-i-create-a-hashmap-literal) to provide it.

-When should I use an implicit return? +我什么时候应该使用隐式 return?

Rust is a very expression-oriented language, and "implicit returns" are part of that design. Constructs like `if`s, `match`es, and normal blocks are all expressions in Rust. For example, the following code checks if an [`i64`][i64] is odd, returning the result by simply yielding it as a value: @@ -297,10 +298,10 @@ In each example, the last line of the function is the return value of that funct Explicit returns are only used if an implicit return is impossible because you are returning before the end of the function's body. While each of the above functions could have been written with a `return` keyword and semicolon, doing so would be unnecessarily verbose, and inconsistent with the conventions of Rust code.

-Why aren't function signatures inferred? +为什么不推断函数签名?

-In Rust, declarations tend to come with explicit types, while actual code has its types inferred. There are several reasons for this design: +在 Rust 中,声明倾向于使用显式类型,而实际代码则推断其类型。这种设计有几个原因: - Mandatory declaration signatures help enforce interface stability at both the module and crate level. - Signatures improve code comprehension for the programmer, eliminating the need for an IDE running an inference algorithm across an entire crate to be able to guess at a function's argument types; it's always explicit and nearby. @@ -325,7 +326,7 @@ match val.do_something() { } ``` -

Numerics

+

数字

Which of f32 and f64 should I prefer for floating-point math? @@ -352,7 +353,7 @@ Because floats do not implement [`Eq`][Eq] or [`Ord`][Ord], they may not be used There [is a crate](https://crates.io/crates/ordered-float) that wraps [`f32`][f32] and [`f64`][f64] to provide [`Ord`][Ord] and [`Eq`][Eq] implementations, which may be useful in certain cases.

-How can I convert between numeric types? +如何在数字类型间进行转换?

There are two ways: the `as` keyword, which does simple casting for primitive types, and the [`Into`][Into] and [`From`][From] traits, which are implemented for a number of type conversions (and which you can implement for your own types). The [`Into`][Into] and [`From`][From] traits are only implemented in cases where conversions are lossless, so for example, `f64::from(0f32)` will compile while `f32::from(0f64)` will not. On the other hand, `as` will convert between any two primitive types, truncating values as necessary. @@ -364,7 +365,7 @@ Why doesn't Rust have increment and decrement operators? Preincrement and postincrement (and the decrement equivalents), while convenient, are also fairly complex. They require knowledge of evaluation order, and often lead to subtle bugs and undefined behavior in C and C++. `x = x + 1` or `x += 1` is only slightly longer, but unambiguous. -

Strings

+

字符串

How can I convert a String or Vec<T> to a slice (&str and &[T])? @@ -395,7 +396,7 @@ fn say_hello(name: &str) { ```

-What are the differences between the two different string types? +两种不同的字符串类型有什么区别?

[`String`][String] is an owned buffer of UTF-8 bytes allocated on the heap. Mutable [`String`s][String] can be modified, growing their capacity as needed. [`&str`][str] is a fixed-capacity "view" into a [`String`][String] allocated elsewhere, commonly on the heap, in the case of slices dereferenced from [`String`s][String], or in static memory, in the case of string literals. @@ -403,17 +404,17 @@ What are the differences between the two different string types? [`&str`][str] is a primitive type implemented by the Rust language, while [`String`][String] is implemented in the standard library.

-How do I do O(1) character access in a String? +如何以 O(1) 复杂度访问一个 String 中的字符?

-You cannot. At least not without a firm understanding of what you mean by "character", and preprocessing the string to find the index of the desired character. +并不能这样做。At least not without a firm understanding of what you mean by "character", and preprocessing the string to find the index of the desired character. Rust strings are UTF-8 encoded. A single visual character in UTF-8 is not necessarily a single byte as it would be in an ASCII-encoded string. Each byte is called a "code unit" (in UTF-16, code units are 2 bytes; in UTF-32 they are 4 bytes). "Code points" are composed of one or more code units, and combine in "grapheme clusters" which most closely approximate characters. Thus, even though you may index on bytes in a UTF-8 string, you can't access the `i`th code point or grapheme cluster in constant time. However, if you know at which byte that desired code point or grapheme cluster begins, then you _can_ access it in constant time. Functions including [`str::find()`][str__find] and regex matches return byte indices, facilitating this sort of access.

-Why are strings UTF-8 by default? +为什么字符串默认为 UTF-8?

The [`str`][str] type is UTF-8 because we observe more text in the wild in this encoding – particularly in network transmissions, which are endian-agnostic – and we think it's best that the default treatment of I/O not involve having to recode codepoints in each direction. @@ -429,33 +430,33 @@ The [`char`][char] type is UTF-32. If you are sure you need to do a codepoint-at For a more in-depth explanation of why UTF-8 is usually preferable over UTF-16 or UTF-32, read the [UTF-8 Everywhere manifesto](http://utf8everywhere.org/).

-What string type should I use? +我应该使用哪种字符串类型?

Rust has four pairs of string types, [each serving a distinct purpose](http://www.suspectsemantics.com/blog/2016/03/27/string-types-in-rust/). In each pair, there is an "owned" string type, and a "slice" string type. The organization looks like this: -| | "Slice" type | "Owned" type | +| | "Slice" 类型 | "Owned" 类型 | |:--------------|:-------------|:-------------| | UTF-8 | `str` | `String` | -| OS-compatible | `OsStr` | `OsString` | -| C-compatible | `CStr` | `CString` | -| System path | `Path` | `PathBuf` | +| OS 兼容 | `OsStr` | `OsString` | +| C 兼容 | `CStr` | `CString` | +| 系统路径 | `Path` | `PathBuf` | -Rust's different string types serve different purposes. `String` and `str` are UTF-8 encoded general-purpose strings. `OsString` and `OsStr` are encoded according to the current platform, and are used when interacting with the operating system. `CString` and `CStr` are the Rust equivalent of strings in C, and are used in FFI code, and `PathBuf` and `Path` are convenience wrappers around `OsString` and `OsStr`, providing methods specific to path manipulation. +Rust 的不同字符串类型适用于不同的目的。`String` 和 `str` 为 UTF-8 编码的通用目的字符串。`OsString` 和 `OsStr` 的编码取决于当前平台,在与操作系统交互时 使用。`CString` 和 `CStr` 是 Rust 中与 C 字符串相当的存在,用于 FFI 代码。`PathBuf` 和 `Path` 是 `OsString` 和 `OsStr` 的方便包装,提供特定路径操作的方法。

-How can I write a function that accepts both &str and String? +怎样写一个同时接受 &strString 的函数?

-There are several options, depending on the needs of the function: +有几种方法,具体取决于该函数的需求: - If the function needs an owned string, but wants to accept any type of string, use an `Into` bound. - If the function needs a string slice, but wants to accept any type of string, use an `AsRef` bound. - If the function does not care about the string type, and wants to handle the two possibilities uniformly, use `Cow` as the input type. -__Using `Into`__ +__使用 `Into`__ -In this example, the function will accept both owned strings and string slices, either doing nothing or converting the input into an owned string within the function body. Note that the conversion needs to be done explicitly, and will not happen otherwise. +在此例中,the function will accept both owned strings and string slices, either doing nothing or converting the input into an owned string within the function body. Note that the conversion needs to be done explicitly, and will not happen otherwise. ```rust fn accepts_both>(s: S) { @@ -464,9 +465,9 @@ fn accepts_both>(s: S) { } ``` -__Using `AsRef`__ +__使用 `AsRef`__ -In this example, the function will accept both owned strings and string slices, either doing nothing or converting the input into a string slice. This can be done automatically by taking the input by reference, like so: +在此例中,the function will accept both owned strings and string slices, either doing nothing or converting the input into a string slice. This can be done automatically by taking the input by reference, like so: ```rust fn accepts_both>(s: &S) { @@ -474,9 +475,9 @@ fn accepts_both>(s: &S) { } ``` -__Using `Cow`__ +__使用 `Cow`__ -In this example, the function takes in a `Cow`, which is not a generic type but a container, containing either an owned string or string slice as needed. +在此例中,该函数采用一个 `Cow`,它不是通用类型,而是一个容器,包含所需的字符串或字符串切片。 ```rust fn accepts_cow(s: Cow) { @@ -485,20 +486,20 @@ fn accepts_cow(s: Cow) { ``` -

Collections

+

集合

-Can I implement data structures like vectors and linked lists efficiently in Rust? +可以在 Rust 中有效地实现向量和链表的数据结构吗?

If your reason for implementing these data structures is to use them for other programs, there's no need, as efficient implementations of these data structures are provided by the standard library. If, however, [your reason is simply to learn](http://cglab.ca/~abeinges/blah/too-many-lists/book/), then you will likely need to dip into unsafe code. While these data structures _can_ be implemented entirely in safe Rust, the performance is likely to be worse than it would be with the use of unsafe code. The simple reason for this is that data structures like vectors and linked lists rely on pointer and memory operations that are disallowed in safe Rust. -For example, a doubly-linked list requires that there be two mutable references to each node, but this violates Rust's mutable reference aliasing rules. You can solve this using [`Weak`][Weak], but the performance will be poorer than you likely want. With unsafe code you can bypass the mutable reference aliasing rule restriction, but must manually verify that your code introduces no memory safety violations. +例如,a doubly-linked list requires that there be two mutable references to each node, but this violates Rust's mutable reference aliasing rules. You can solve this using [`Weak`][Weak], but the performance will be poorer than you likely want. With unsafe code you can bypass the mutable reference aliasing rule restriction, but must manually verify that your code introduces no memory safety violations.

-How can I iterate over a collection without moving/consuming it? +如何在不移动/消费的情况下迭代集合?

The easiest way is by using the collection's [`IntoIterator`][IntoIterator] implementation. Here is an example for [`&Vec`][Vec]: @@ -511,14 +512,14 @@ for item in &v { println!("\nLength: {}", v.len()); ``` -Rust `for` loops call `into_iter()` (defined on the [`IntoIterator`][IntoIterator] trait) for whatever they're iterating over. Anything implementing the [`IntoIterator`][IntoIterator] trait may be looped over with a `for` loop. [`IntoIterator`][IntoIterator] is implemented for [`&Vec`][Vec] and [`&mut Vec`][Vec], causing the iterator from `into_iter()` to borrow the contents of the collection, rather than moving/consuming them. The same is true for other standard collections as well. +Rust `for` 循环调用 `into_iter()` (defined on the [`IntoIterator`][IntoIterator] trait) for whatever they're iterating over. Anything implementing the [`IntoIterator`][IntoIterator] trait may be looped over with a `for` loop. [`IntoIterator`][IntoIterator] is implemented for [`&Vec`][Vec] and [`&mut Vec`][Vec], causing the iterator from `into_iter()` to borrow the contents of the collection, rather than moving/consuming them. The same is true for other standard collections as well. -If a moving/consuming iterator is desired, write the `for` loop without `&` or `&mut` in the iteration. +如果需要移动/消费迭代器,在迭代中撰写没有 `&` 或 `&mut` 的 `for`。 -If you need direct access to a borrowing iterator, you can usually get it by calling the `iter()` method. +如果您需要直接访问一个借用的迭代器,您通常可以调用 `iter()` 方法来获取它。

-Why do I need to type the array size in the array declaration? +为什么需要在数组声明中键入数组大小?

You don't necessarily have to. If you're declaring an array directly, the size is inferred based on the number of elements. But if you're declaring a function that takes a fixed-size array, the compiler has to know how big that array will be. @@ -528,23 +529,22 @@ One thing to note is that currently Rust doesn't offer generics over arrays of d

Ownership

-How can I implement a graph or other data structure that contains cycles? +如何实现包含循环的图或其他数据结构?

There are at least four options (discussed at length in [Too Many Linked Lists](http://cglab.ca/~abeinges/blah/too-many-lists/book/)): -- You can implement it using [`Rc`][Rc] and [`Weak`][Weak] to allow shared ownership of nodes, -although this approach pays the cost of memory management. +- 您可以使用 [`Rc`][Rc] 和 [`Weak`][Weak] 来允许节点共享所有权以实现它。虽然这种方法要支付内存管理的成本。 - You can implement it using `unsafe` code using raw pointers. This will be more efficient, but bypasses Rust's safety guarantees. - Using vectors and indices into those vectors. There are [several](http://smallcultfollowing.com/babysteps/blog/2015/04/06/modeling-graphs-in-rust-using-vector-indices/) [available](https://featherweightmusings.blogspot.com/2015/04/graphs-in-rust.html) examples and explanations of this approach. - Using borrowed references with [`UnsafeCell`][UnsafeCell]. There are [explanations and code](https://github.com/nrc/r4cppp/blob/master/graphs/README.md#node-and-unsafecell) available for this approach.

-How can I define a struct that contains a reference to one of its own fields? +我该如何定义一个包含对其自身字段之一引用的结构体?

-It's possible, but useless to do so. The struct becomes permanently borrowed by itself and therefore can't be moved. Here is some code illustrating this: +这有可能,但没有用。结构本身是永久借用,因此无法移动。下面用一些代码说明: ```rust use std::cell::Cell; @@ -565,19 +565,19 @@ fn main() { ```

-What is the difference between passing by value, consuming, moving, and transferring ownership? +按值传递,消费,移动和转让所有权之间有什么区别?

These are different terms for the same thing. In all cases, it means the value has been moved to another owner, and moved out of the possession of the original owner, who can no longer use it. If a type implements the `Copy` trait, the original owner's value won't be invalidated, and can still be used.

-Why can values of some types be used after passing them to a function, while reuse of values of other types results in an error? +为什么某些类型的值在传递到一个函数后可以使用,而另一些类型的值传递后使用会导致错误?

-If a type implements the [`Copy`][Copy] trait, then it will be copied when passed to a function. All numeric types in Rust implement [`Copy`][Copy], but struct types do not implement [`Copy`][Copy] by default, so they are moved instead. This means that the struct can no longer be used elsewhere, unless it is moved back out of the function via the return. +如果一个类型实现了 [`Copy`][Copy] 特征,则它将在传递到一个函数时被复制。Rust 中的所有数字类型都实现了 [`Copy`][Copy],但结构类型默认并未实现 [`Copy`][Copy],因此它们是被移动。这意味着结构体不能在其他地方重用,除非它是通过 return 从函数中移出。

-How do you deal with a "use of moved value" error? +如何处理“use of moved value”错误?

This error means that the value you're trying to use has been moved to a new owner. The first thing to check is whether the move in question was necessary: if it moved into a function, it may be possible to rewrite the function to use a reference, rather than moving. Otherwise if the type being moved implements [`Clone`][Clone], then calling `clone()` on it before moving will move a copy of it, leaving the original still available for further use. Note though that cloning a value should typically be the last resort since cloning can be expensive, causing further allocations. @@ -587,18 +587,18 @@ If the moved value is of your own custom type, consider implementing [`Copy`][Co If none of these are possible, you may want to modify the function that acquired ownership to return ownership of the value when the function exits.

-What are the rules for using self, &self, or &mut self in a method declaration? +在方法声明中使用 self&self&mut self 的规则是什么?

-- Use `self` when a function needs to consume the value -- Use `&self` when a function only needs a read-only reference to the value -- Use `&mut self` when a function needs to mutate the value without consuming it +- 使用 `self`,当一个函数需要消费该值 +- 使用 `&self`,当一个函数只需要该值的只读引用 +- 使用 `&mut self`,当一个函数不需消费而要变更该值

-How can I understand the borrow checker? +我该怎么能理解借用检查器?

-The borrow checker applies only a few rules, which can be found in the Rust book's [section on borrowing](https://doc.rust-lang.org/stable/book/references-and-borrowing.html#the-rules), when evaluating Rust code. These rules are: +借用检查器只使用几条规则,而这可以在 Rust 之书的[借用部分](https://doc.rust-lang.org/stable/book/references-and-borrowing.html#the-rules)找到,当评估(Eval) Rust 代码时。这些规则为: > First, any borrow must last for a scope no greater than that of the owner. Second, you may have one or the other of these two kinds of borrows, but not both at the same time: > @@ -616,19 +616,19 @@ The single most important part of understanding the borrow checker is practice. If you find yourself struggling with the borrow checker, or running out of patience, always feel free to reach out to the [Rust community](community.html) for help.

-When is Rc useful? +Rc 在什么时候有用?

This is covered in the official documentation for [`Rc`][Rc], Rust's non-atomically reference-counted pointer type. In short, [`Rc`][Rc] and its thread-safe cousin [`Arc`][Arc] are useful to express shared ownership, and have the system automatically deallocate the associated memory when no one has access to it.

-How do I return a closure from a function? +如何从函数返回一个闭包?

To return a closure from a function, it must be a "move closure", meaning that the closure is declared with the `move` keyword. As [explained in the Rust book](https://doc.rust-lang.org/book/closures.html#move-closures), this gives the closure its own copy of the captured variables, independent of its parent stack frame. Otherwise, returning a closure would be unsafe, as it would allow access to variables that are no longer valid; put another way: it would allow reading potentially invalid memory. The closure must also be wrapped in a [`Box`][Box], so that it is allocated on the heap. Read more about this [in the book](https://doc.rust-lang.org/book/closures.html#returning-closures).

-What is a deref coercion and how does it work? +什么是强制退还,它是如何工作?

A [deref coercion](https://doc.rust-lang.org/book/deref-coercions.html) is a handy coercion @@ -651,22 +651,22 @@ The most common sorts of deref coercions are: - `&Vec` to `&[T]` - `&String` to `&str` -

Lifetimes

+

生命周期

-Why lifetimes? +为什么有生命周期?

Lifetimes are Rust's answer to the question of memory safety. They allow Rust to ensure memory safety without the performance costs of garbage collection. They are based on a variety of academic work, which can be found in the [Rust book](https://doc.rust-lang.org/stable/book/bibliography.html#type-system).

-Why is the lifetime syntax the way it is? +为什么生命周期语法是这样的?

The `'a` syntax comes from the ML family of programming languages, where `'a` is used to indicate a generic type parameter. For Rust, the syntax had to be something that was unambiguous, noticeable, and fit nicely in a type declaration right alongside traits and references. Alternative syntaxes have been discussed, but no alternative syntax has been demonstrated to be clearly better.

-How do I return a borrow to something I created from a function? +如何将一个函数中创建的东西返回为借用?

You need to ensure that the borrowed item will outlive the function. This can be done by binding the output lifetime to some input lifetime like so: @@ -692,10 +692,10 @@ fn happy_birthday(name: &str, age: i64) -> String { } ``` -This approach is simpler, but often results in unnecessary allocations. +这种方法更简单,但往往导致不必要的分配。

-Why do some references have lifetimes, like &'a T, and some do not, like &T? +为什么某些引用有生命周期,比如 &'a T,而某些没有,比如 &T

In fact, *all* reference types have a lifetime, but most of the time you do not have to write @@ -720,21 +720,21 @@ it explicitly. The rules are as follows: If these rules result in compilation errors, the Rust compiler will provide an error message indicating the error caused, and suggesting a potential solution based on which step of the inference process caused the error.

-How can Rust guarantee "no null pointers" and "no dangling pointers"? +Rust 如何保证“无空指针”和“无悬挂指针”?

The only way to construct a value of type `&Foo` or `&mut Foo` is to specify an existing value of type `Foo` that the reference points to. The reference "borrows" the original value for a given region of code (the lifetime of the reference), and the value being borrowed from cannot be moved or destroyed for the duration of the borrow.

-How do I express the absence of a value without null? +如果没有 null,我该怎么表达缺失值?

You can do that with the [`Option`][Option] type, which can either be `Some(T)` or `None`. `Some(T)` indicates that a value of type `T` is contained within, while `None` indicates the absence of a value. -

Generics

+

泛型

-What is "monomorphisation"? +什么是“单态化”?

Monomorphisation specializes each use of a generic function (or structure) with specific instance, @@ -745,7 +745,7 @@ During monomorphisation a new copy of the generic function is translated for eac Functions that accept [trait objects](https://doc.rust-lang.org/book/trait-objects.html) instead of type parameters do not undergo monomorphisation. Instead, methods on the trait objects are dispatched dynamically at runtime.

-What's the difference between a function and a closure that doesn't capture any variables? +一个函数和一个没有捕获任何变量的闭包有什么区别?

Functions and closures are operationally equivalent, but have different runtime representations due to their differing implementations. @@ -757,7 +757,7 @@ The big difference between these traits is how they take the `self` parameter. [ Even if a closure does not capture any environment variables, it is represented at runtime as two pointers, the same as any other closure.

-What are higher-kinded types, why would I want them, and why doesn't Rust have them? +什么是更高级的类型,为什么我想要它们,为什么 Rust 没有它们?

Higher-kinded types are types with unfilled parameters. Type constructors, like [`Vec`][Vec], [`Result`][Result], and [`HashMap`][HashMap] are all examples of higher-kinded types: each requires some additional type parameters in order to actually denote a specific type, like `Vec`. Support for higher-kinded types means these "incomplete" types may be used anywhere "complete" types can be used, including as generics for functions. @@ -773,7 +773,7 @@ Another common example is concepts like functors or monads, both of which are ty Rust doesn't currently have support for higher-kinded types because it hasn't been a priority compared to other improvements we want to make. Since the design is a major, cross-cutting change, we also want to approach it carefully. But there's no inherent reason for the current lack of support.

-What do named type parameters like <T=Foo> in generic types mean? +通用类型中 <T=Foo> 这样的命名类型参数是什么意思?

These are called [associated types](https://doc.rust-lang.org/stable/book/associated-types.html), and they allow for the expression of trait bounds that can't be expressed with a `where` clause. For example, a generic bound `X: Bar` means "`X` must implement the trait `Bar`, and in that implementation of `Bar`, `X` must choose `Foo` for `Bar`'s associated type, `T`." Examples of where such a constraint cannot be expressed via a `where` clause include trait objects like `Box>`. @@ -781,7 +781,7 @@ These are called [associated types](https://doc.rust-lang.org/stable/book/associ Associated types exist because generics often involve families of types, where one type determines all of the others in a family. For example, a trait for graphs might have as its `Self` type the graph itself, and have associated types for nodes and for edges. Each graph type uniquely determines the associated types. Using associated types makes it much more concise to work with these families of types, and also provides better type inference in many cases.

-Can I overload operators? Which ones and how? +我可以重载运算符吗?哪些可以,怎么做?

You can provide custom implementations for a variety of operators using their associated traits: [`Add`][Add] for `+`, [`Mul`][Mul] for `*`, and so on. It looks like this: @@ -840,10 +840,10 @@ Floating point types ([`f32`][f32] and [`f64`][f64]) are good examples of each. As explained in [the earlier question on floats](#why-cant-i-compare-floats), these distinctions are important because some collections rely on total orderings/equality in order to give correct results. -

Input / Output

+

输入 / 输出

-How do I read a file into a String? +如何将文件读入一个 String

Using the [`read_to_string()`][read__read_to_string] method, which is defined on the [`Read`][Read] trait in [`std::io`][std-io]. @@ -868,7 +868,7 @@ fn main() { ```

-How do I read file input efficiently? +如何有效地读取文件输入?

The [`File`][File] type implements the [`Read`][Read] trait, which has a variety of functions for reading and writing data, including [`read()`][read__read], [`read_to_end()`][read__read_to_end], [`bytes()`][read__bytes], [`chars()`][read__chars], and [`take()`][read__take]. Each of these functions reads a certain amount of input from a given file. [`read()`][read__read] reads as much input as the underlying system will provide in a single call. [`read_to_end()`][read__read_to_end] reads the entire buffer into a vector, allocating as much space as is needed. [`bytes()`][read__bytes] and [`chars()`][read__chars] allow you to iterate over the bytes and characters of the file, respectively. Finally, [`take()`][read__take] allows you to read up to an arbitrary number of bytes from the file. Collectively, these should allow you to efficiently read in any data you need. @@ -876,23 +876,23 @@ The [`File`][File] type implements the [`Read`][Read] trait, which has a variety For buffered reads, use the [`BufReader`][BufReader] struct, which helps to reduce the number of system calls when reading.

-How do I do asynchronous input / output in Rust? +Rust 中如何进行异步输入/输出?

There are several libraries providing asynchronous input / output in Rust, including [mioco](https://github.com/dpc/mioco), [coio-rs](https://github.com/zonyitoo/coio-rs), and [rotor](https://github.com/tailhook/rotor).

-How do I get command line arguments in Rust? +如何在 Rust 中获取命令行参数?

The easiest way is to use [`Args`][Args], which provides an iterator over the input arguments. If you're looking for something more powerful, there are a [number of options on crates.io](https://crates.io/keywords/argument). -

Error Handling

+

错误处理

-Why doesn't Rust have exceptions? +为什么 Rust 没有异常?

Exceptions complicate understanding of control-flow, they express validity/invalidity outside of the type system, and they interoperate poorly with multithreaded code (a major focus of Rust). @@ -910,7 +910,7 @@ What's the deal with unwrap() everywhere? It's also useful for quick prototypes where you don't want to handle an error yet, or blog posts where error handling would distract from the main point.

-Why do I get an error when I try to run example code that uses the try! macro? +为什么我尝试运行使用 try! 宏的示例代码时收到错误?

It's probably an issue with the function's return type. The [`try!`][TryMacro] macro either extracts the value from a [`Result`][Result], or returns early with the error [`Result`][Result] is carrying. This means that [`try`][TryMacro] only works for functions that return [`Result`][Result] themselves, where the `Err`-constructed type implements `From::from(err)`. In particular, this means that the [`try!`][TryMacro] macro cannot work inside the `main` function. @@ -923,7 +923,7 @@ If you're looking for a way to avoid handling [`Result`s][Result] in other peopl If you really don't want to handle an error, use [`unwrap()`][unwrap], but know that doing so means that the code panics on failure, which usually results in a shutting down the process. -

Concurrency

+

并发

Can I use static values across threads without an unsafe block? @@ -933,7 +933,7 @@ Mutation is safe if it's synchronized. Mutating a static [`Mutex`][Mutex] (lazil More generally, if a type implements [`Sync`][Sync] and does not implement [`Drop`][Drop], it [can be used in a `static`](https://doc.rust-lang.org/book/const-and-static.html#static). -

Macros

+

Can I write a macro to generate identifiers? @@ -941,10 +941,10 @@ Can I write a macro to generate identifiers? Not currently. Rust macros are ["hygienic macros"](https://en.wikipedia.org/wiki/Hygienic_macro), which intentionally avoid capturing or creating identifiers that may cause unexpected collisions with other identifiers. Their capabilities are significantly different than the style of macros commonly associated with the C preprocessor. Macro invocations can only appear in places where they are explicitly supported: items, method declarations, statements, expressions, and patterns. Here, "method declarations" means a blank space where a method can be put. They can't be used to complete a partial method declaration. By the same logic, they can't be used to complete a partial variable declaration. -

Debugging and Tooling

+

调试和工具

-How do I debug Rust programs? +如何调试 Rust 程序?

Rust programs can be debugged using [gdb](https://sourceware.org/gdb/current/onlinedocs/gdb/) or [lldb](http://lldb.llvm.org/tutorial.html), the same as C and C++. In fact, every Rust installation comes with one or both of rust-gdb and rust-lldb (depending on platform support). These are wrappers over gdb and lldb with Rust pretty-printing enabled. @@ -956,10 +956,10 @@ Rust programs can be debugged using [gdb](https://sourceware.org/gdb/current/onl This error is usually caused by [`unwrap()`ing][unwrap] a `None` or `Err` in client code. Enabling backtraces by setting the environment variable `RUST_BACKTRACE=1` helps with getting more information. Compiling in debug mode (the default for `cargo build`) is also helpful. Using a debugger like the provided `rust-gdb` or `rust-lldb` is also helpful.

-What IDE should I use? +我该使用什么 IDE?

-There are a number of options for development environment with Rust, all of which are detailed on the official [IDE support page](https://forge.rust-lang.org/ides.html). +Rust 有许多开发环境可供选择,详见官方的 [IDE 支持页面](https://forge.rust-lang.org/ides.html)。

gofmt is great. Where's rustfmt? @@ -967,39 +967,39 @@ There are a number of options for development environment with Rust, all of whic `rustfmt` is [right here](https://github.com/rust-lang-nursery/rustfmt), and is being actively developed to make reading Rust code as easy and predictable as possible. -

Low-Level

+

底层

-How do I memcpy bytes? +如何 memcpy 字节?

-If you want to clone an existing slice safely, you can use [`clone_from_slice`][clone_from_slice]. +如果您想安全地克隆现有切片,可以使用 [`clone_from_slice`][clone_from_slice]。 -To copy potentially overlapping bytes, use [`copy`][copy]. To copy nonoverlapping bytes, use [`copy_nonoverlapping`][copy_nonoverlapping]. Both of these functions are `unsafe`, as both can be used to subvert the language's safety guarantees. Take care when using them. +要复制可能重叠的字节,使用 [`copy`][copy]. 要复制非重叠字节,使用 [`copy_nonoverlapping`][copy_nonoverlapping]。两个特性都是 `unsafe`,因此两者都可以颠覆本语言的安全保障,使用时请小心。

-Can Rust function reasonably without the standard library? +没有标准库的 Rust 还有适当的功能吗?

-Absolutely. Rust programs can be set to not load the standard library using the `#![no_std]` attribute. With this attribute set, you can continue to use the Rust core library, which is nothing but the platform-agnostic primitives. As such, it doesn't include IO, concurrency, heap allocation, etc. +绝对可以。Rust 程序可以使用 `#![no_std]` 属性设置为不加载标准库。使用此属性集后,您可以继续使用 Rust 核心库,那些是与平台无关的原函数。也因此,它不包括 IO、并发、堆分配等。

-Can I write an operating system in Rust? +我可以用 Rust 写一个操作系统吗?

-Yes! In fact there are [several projects underway doing just that](http://wiki.osdev.org/Rust). +行的!事实上,[有多个项目正在进行中](http://wiki.osdev.org/Rust)。

-How can I read or write numeric types like i32 or f64 in big-endian or little-endian format in a file or other byte stream? +如何以大端或小端格式读取与写入一个文件或其他字节流中的是 i32f64 这样的数字类型?

-You should check out the [byteorder crate](http://burntsushi.net/rustdoc/byteorder/), which provides utilities for exactly that. +您应该检出 [byteorder 包装箱](http://burntsushi.net/rustdoc/byteorder/),它提供了这种实用程序。

-Does Rust guarantee a specific data layout? +Rust 是否保证特定的数据布局?

-Not by default. In the general case, `enum` and `struct` layouts are undefined. This allows the compiler to potentially do optimizations like re-using padding for the discriminant, compacting variants of nested `enum`s, reordering fields to remove padding, etc. `enums` which carry no data ("C-like") are eligible to have a defined representation. Such `enums` are easily distinguished in that they are simply a list of names that carry no data: +默认不会。在一般情况下,`enum` 和 `struct` 布局是未定义的。这允许编译器进行潜在优化,例如重新使用 padding for the discriminant, compacting variants of nested `enum`s, reordering fields to remove padding, etc. `enums` which carry no data ("C-like") are eligible to have a defined representation. Such `enums` are easily distinguished in that they are simply a list of names that carry no data: ```rust enum CLike { @@ -1010,9 +1010,9 @@ enum CLike { } ``` -The `#[repr(C)]` attribute can be applied to such `enums` to give them the same representation they would have in equivalent C code. This allows using Rust `enum`s in FFI code where C `enum`s are also used, for most use cases. The attribute can also be applied to `struct`s to get the same layout as a C `struct` would. +`#[repr(C)]` 属性可以应用到诸如 `enums` 以提供等同 C 语言中的表示。This allows using Rust `enum`s in FFI code where C `enum`s are also used, for most use cases. The attribute can also be applied to `struct`s to get the same layout as a C `struct` would. -

Cross-Platform

+

跨平台

-What's the idiomatic way to express platform-specific behavior in Rust? +在 Rust 中表达特定平台行为的惯用方式是什么?

-Platform-specific behavior can be expressed using [conditional compilation attributes](https://doc.rust-lang.org/reference/attributes.html#conditional-compilation) such as `target_os`, `target_family`, `target_endian`, etc. +特定平台的行为可以使用[条件编译属性](https://doc.rust-lang.org/reference/attributes.html#conditional-compilation),诸如 `target_os`、`target_family`、`target_endian` 等。

-Can Rust be used for Android/iOS programming? +Rust 可以用于 Android/iOS 编程吗?

-Yes it can! There are already examples of using Rust for both [Android](https://github.com/tomaka/android-rs-glue) and [iOS](https://www.bignerdranch.com/blog/building-an-ios-app-in-rust-part-1/). It does require a bit of work to set up, but Rust functions fine on both platforms. +可以!已经有为 [Android](https://github.com/tomaka/android-rs-glue) 和 [iOS](https://www.bignerdranch.com/blog/building-an-ios-app-in-rust-part-1/) 使用 Rust 的例子。它需要一些工作来完成设置,但是 Rust 在这两个平台上都能正常工作。

-Can I run my Rust program in a web browser? +我可以在网页浏览器中运行我的 Rust 程序吗?

-Not yet, but there are efforts underway to make Rust compile to the web with [Emscripten](https://kripken.github.io/emscripten-site/). +目前还不行,但也正在努力使 Rust 能用 [Emscripten](https://kripken.github.io/emscripten-site/) 编译为 Web 版。

-How do I cross-compile in Rust? +如何在 Rust 中交叉编译?

-Cross compilation is possible in Rust, but it requires [a bit of work](https://github.com/japaric/rust-cross/blob/master/README.md) to set up. Every Rust compiler is a cross-compiler, but libraries need to be cross-compiled for the target platform. +Rust 的交叉编译是可能的,它但需要[一些流程](https://github.com/japaric/rust-cross/blob/master/README.md)完成设置。每个 Rust 编译器都是一个交叉编译器,但库需要针对目标平台进行交叉编译。 -Rust does distribute [copies of the standard library](https://static.rust-lang.org/dist/index.html) for each of the supported platforms, which are contained in the `rust-std-*` files for each of the build directories found on the distribution page, but there are not yet automated ways to install them. +Rust 确实为每个受支持平台方法[标准库副本](https://static.rust-lang.org/dist/index.html),在分发目录上可以找到各构建目录,其中包含的 `rust-std-*` 文件就是它们,但尚没有自动安装它们的方法。 -

Modules and Crates

+

模块和包装箱

-What is the relationship between a module and a crate? +模块与包装箱之间的关系是什么?

-- A crate is a compilation unit, which is the smallest amount of code that the Rust compiler can operate on. -- A module is a (possibly nested) unit of code organization inside a crate. -- A crate contains an implicit, un-named top-level module. -- Recursive definitions can span modules, but not crates. +- 一个包装箱是一个编译单元,它是 Rust 编译器可操作的最小代码量。 +- 一个模块是一个(可能是嵌套的)放在一个包装箱内的代码单元。 +- 一个包装箱包含一个隐含的、未命名的顶层模块。 +- 递归定义可以跨越模块,但不能跨包装箱。

-Why can't the Rust compiler find this library I'm useing? +为什么 Rust 编译器找不到我 use 的库?

There are a number of possible answers, but a common mistake is not realizing that `use` declarations are relative to the crate root. Try rewriting your declarations to use the paths they would use if defined in the root file of your project and see if that fixes the problem. @@ -1074,10 +1074,10 @@ There are also `self` and `super`, which disambiguate `use` paths as being relat For complete information on `use`ing libraries, read the Rust book's chapter ["Crates and Modules"](https://doc.rust-lang.org/stable/book/crates-and-modules.html).

-Why do I have to declare module files with mod at the top level of the crate, instead of just useing them? +为什么我必须在包装箱顶层用 mod 声明模块文件,而不能直接 use 它们?

-There are two ways to declare modules in Rust, inline or in another file. Here is an example of each: +有两种方法在 Rust 中声明模块:内链或者另一个文件。下面是两个例子: ```rust // In main.rs @@ -1106,24 +1106,24 @@ pub fn f() { } ``` -In the first example, the module is defined in the same file it's used. In the second example, the module declaration in the main file tells the compiler to look for either `hello.rs` or `hello/mod.rs`, and to load that file. +在第一个例子中,模块在其使用的同一个文件中定义。第二个例子中,主文件中的模块声明告诉编译器找到 `hello.rs` 或 `hello/mod.rs`,然后加载该文件。 -Note the difference between `mod` and `use`: `mod` declares that a module exists, whereas `use` references a module declared elsewhere, bringing its contents into scope within the current module. +注意 `mod` 与 `use` 的差异:`mod` 声明一个模块的存在,而 `use` 引用一个在别处声明的模块,将其内容纳入到当前模块的范围。

-How do I configure Cargo to use a proxy? +如何配置 Cargo 使用代理服务器?

-As explained on the Cargo [configuration documentation](http://doc.crates.io/config.html), you can set Cargo to use a proxy by setting the "proxy" variable under `[http]` in the configuration file. +正如 Cargo 的[配置文档](http://doc.crates.io/config.html)所说,您可以设置配置文件中 `[http]` 下的“proxy”变量使 Cargo 使用一个代理服务器。

-Why can't the compiler find the method implementation even though I'm already useing the crate? +为什么编译器找不到方法实现,即使我已经 use 包装箱?

For methods defined on a trait, you have to explicitly import the trait declaration. This means it's not enough to import a module where a struct implements the trait, you must also import the trait itself.

-Why can't the compiler infer use declarations for me? +为什么编译器不能为我推断 use 声明?

It probably could, but you also don't want it to. While in many cases it is likely that the compiler could determine the correct module to import by simply looking for where a given identifier is defined, this may not be the case in general. Any decision rule in `rustc` for choosing between competing options would likely cause surprise and confusion in some cases, and Rust prefers to be explicit about where names are coming from. @@ -1143,7 +1143,7 @@ fn main() { If you know this is going to happen, perhaps it saves a small number of keystrokes, but it also greatly increases the possibility for surprising error messages when you actually meant for `baz()` to be `bar::baz()`, and it decreases the readability of the code by making the meaning of a function call dependent on module declaration. These are not tradeoffs we are willing to make. -However, in the future, an IDE could help manage declarations, which gives you the best of both worlds: machine assistance for pulling in names, but explicit declarations about where those names are coming from. +但在未来,IDE 可以帮助管理声明,这会在两方面带来更好的结果:机器人帮忙拉取名称,并明确声明这些名称来自何处。

-How do I do dynamic Rust library loading? +如何动态加载 Rust 库?

-Import dynamic libraries in Rust with [libloading](https://crates.io/crates/libloading), which provides a cross-platform system for dynamic linking. +在 Rust 中使用 [libloading](https://crates.io/crates/libloading) 导入动态库,它提供了一个用于动态链接的跨平台系统。

-Why doesn't crates.io have namespaces? +为什么 crates.io 没有名字空间?

Quoting the [official explanation](https://internals.rust-lang.org/t/crates-io-package-policies/1041) of [https://crates.io](https://crates.io)'s design: @@ -1173,83 +1173,83 @@ Quoting the [official explanation](https://internals.rust-lang.org/t/crates-io-p > > Because namespaces are strictly more complicated in a number of ways, and because they can be added compatibly in the future should they become necessary, we're going to stick with a single shared namespace. -

Libraries

+

-How can I make an HTTP request? +我该怎样发出一个 HTTP 请求?

-The standard library does not include an implementation of HTTP, so you will want to use an external crate. [Hyper](https://github.com/hyperium/hyper) is the most popular, but there are [a number of others as well](https://crates.io/keywords/http). +标准库不包含 HTTP 的实现,因此您需要用外部的包装箱。 [Hyper](https://github.com/hyperium/hyper) 是最流行的选择,但[也有众多其他可选](https://crates.io/keywords/http)。

-How can I write a GUI application in Rust? +如何用 Rust 编写 GUI 应用程序?

-There are a variety of ways to write GUI applications in Rust. Just check out [this list of GUI frameworks](https://github.com/kud1ing/awesome-rust#gui). +有多种方法在 Rust 中编写 GUI 应用程序。查阅我们的[GUI 框架列表](https://github.com/kud1ing/awesome-rust#gui)吧。

-How can I parse JSON/XML? +如何解析 JSON/XML?

-[Serde](https://github.com/serde-rs/serde) is the recommended library for serialization and deserialization of Rust data to and from a number of different formats. +[Serde](https://github.com/serde-rs/serde) 是推荐的将 Rust 数据序列化与反序列化为多种格式的库。

-Is there a standard 2D+ vector and shape crate? +有标准的 2D+ 矢量和形状包装箱吗?

-Not yet! Want to write one? +还没有呢!你能写一个吗?

-How do I write an OpenGL app in Rust? +如何用 Rust 编写 OpenGL 应用程序?

[Glium](https://github.com/tomaka/glium) is the major library for OpenGL programming in Rust. [GLFW](https://github.com/bjz/glfw-rs) is also a solid option.

-Can I write a video game in Rust? +我能用 Rust 编写一个电子游戏吗?

-Yes you can! The major game programming library for Rust is [Piston](http://www.piston.rs/), and there's both a [subreddit for game programming in Rust](https://www.reddit.com/r/rust_gamedev/) and an IRC channel (`#rust-gamedev` on [Mozilla IRC](https://wiki.mozilla.org/IRC)) as well. +没问题!Rust 主要的游戏编程库是 [Piston](http://www.piston.rs/),另有 [Rust 游戏编程的 reddit 板块](https://www.reddit.com/r/rust_gamedev/) 和 IRC 频道([Mozilla IRC](https://wiki.mozilla.org/IRC) 上的 `#rust-gamedev`)。 -

Design Patterns

+

设计模式

-Is Rust object oriented? +Rust 是面向对象吗?

-It is multi-paradigm. Many things you can do in OO languages you can do in Rust, but not everything, and not always using the same abstraction you're accustomed to. +它是多范式。你在面向对象(OO)语言中做的许多事情也能在 Rust 中做,但并不是所有都可以,并且不一定是你熟悉的方式。

-How do I map object-oriented concepts to Rust? +如何将面向对象的概念映射到 Rust?

That depends. There _are_ ways of translating object-oriented concepts like [multiple inheritance](https://www.reddit.com/r/rust/comments/2sryuw/ideaquestion_about_multiple_inheritence/) to Rust, but as Rust is not object-oriented the result of the translation may look substantially different from its appearance in an OO language.

-How do I handle configuration of a struct with optional parameters? +如何处理有可选参数的结构体的配置?

The easiest way is to use the [`Option`][Option] type in whatever function you're using to construct instances of the struct (usually `new()`). Another way is to use the [builder pattern](https://aturon.github.io/ownership/builders.html), where only certain functions instantiating member variables must be called before the construction of the built type.

-How do I do global variables in Rust? +如何在 Rust 中做全局对象?

-Globals in Rust can be done using `const` declarations for compile-time computed global constants, while `static` can be used for mutable globals. Note that modifying a `static mut` variable requires the use of `unsafe`, as it allows for data races, one of the things guaranteed not to happen in safe Rust. One important distinction between `const` and `static` values is that you can take references to `static` values, but not references to `const` values, which don't have a specified memory location. For more information on `const` vs. `static`, read [the Rust book](https://doc.rust-lang.org/book/const-and-static.html). +Rust 中可以用 `const` 声明在编译时计算的全局常量,而 `static` 可用于可变的全局变量。请注意,修改一个 `static mut` 变量需要使用 `unsafe`,因为它允许数据竞争(races), one of the things guaranteed not to happen in safe Rust. `const` 与 `static` 值的一项重要区别是,你可以引用 `static` 值,但不能引用 `const` 值,因为它没有一个特定的内存位置。有关 `const` 与 `static` 的更多信息,请阅读 [Rust 之书](https://doc.rust-lang.org/book/const-and-static.html)。

-How can I set compile-time constants that are defined procedurally? +如何设置程序定义的编译时的常量?

-Rust currently has limited support for compile time constants. You can define primitives using `const` declarations (similar to `static`, but immutable and without a specified location in memory) as well as define `const` functions and inherent methods. +Rust 目前对编译时常量的支持有限。您可以使用 `const` 声明(类似 `static`,但它不可变,并且在内存中没有特定位置)定义原函数,以及定义 `const` 函数和固有方法。 To define procedural constants that can't be defined via these mechanisms, use the [`lazy-static`](https://github.com/rust-lang-nursery/lazy-static.rs) crate, which emulates compile-time evaluation by automatically evaluating the constant at first use.

-Can I run initialization code that happens before main? +我可以在 main 发生前运行初始化代码吗?

-Rust has no concept of "life before `main`". The closest you'll see can be done through the [`lazy-static`](https://github.com/Kimundi/lazy-static.rs) crate, which simulates a "before main" by lazily initializing static variables at their first usage. +Rust 没有“`main` 之前”的概念。你想找到的最接近的可能是 [`lazy-static`](https://github.com/Kimundi/lazy-static.rs) 包装箱,它在初次使用时通过懒惰初始化静态变量做到类似“在main之前”。

-Does Rust allow non-constant-expression values for globals? +Rust 是否允许全局的非常量表达式值?

No. Globals cannot have a non-constant-expression constructor and cannot have a destructor at all. Static constructors are undesirable because portably ensuring a static initialization order is difficult. Life before main is often considered a misfeature, so Rust does not allow it. See the [C++ FQA](http://yosefk.com/c++fqa/ctors.html#fqa-10.12) about the "static initialization order fiasco", and [Eric Lippert's blog](https://ericlippert.com/2013/02/06/static-constructors-part-one/) for the challenges in C#, which also has this feature. -You can approximate non-constant-expression globals with the [lazy-static](https://crates.io/crates/lazy_static/) crate. +您可以以 [lazy-static](https://crates.io/crates/lazy_static/) 包装箱使用近似的非常量表达式全局对象。 -

Other Languages

+

其他语言

-How can I implement something like C's struct X { static int X; }; in Rust? +如何在 Rust 中实现类似 C 的 struct X { static int X; };

-Rust does not have `static` fields as shown in the code snippet above. Instead, you can declare a `static` variable in a given module, which is kept private to that module. +如上所说,Rust 没有 `static` 字段。不过,您可以在指定的模块中声明一个 `static` 变量,这样它将为该模块私有。

-How can I convert a C-style enum to an integer, or vice-versa? +如何将 C 风格的枚举转换为整数,反之亦然?

Converting a C-style enum to an integer can be done with an `as` expression, like `e as i64` (where `e` is some enum). @@ -1296,7 +1296,7 @@ Converting a C-style enum to an integer can be done with an `as` expression, lik Converting in the other direction can be done with a `match` statement, which maps different numeric values to different potential values for the enum.

-Why do Rust programs use more memory than C? +为什么 Rust 程序使用比 C 更多的内存?

There are several factors that contribute to Rust programs having, by default, larger binary sizes than functionally-equivalent C programs. In general, Rust's preference is to optimize for the performance of real-world programs, not the size of small programs. @@ -1318,7 +1318,7 @@ fn main() { Two distinct versions of `foo` will be in the final binary, one specialized to an `i32` input, one specialized to a `&str` input. This enables efficient static dispatch of the generic function, but at the cost of a larger binary. -__Debug symbols__ +__调试符号__ Rust programs compile with some debug symbols retained, even when compiling in release mode. These are used for providing backtraces on panics, and can be removed with `strip`, or another debug symbol removal tool. It is also useful to note that compiling in release mode with Cargo is equivalent to setting optimization level 3 with rustc. An alternative optimization level (called `s` or `z`) [has recently landed](https://github.com/rust-lang/rust/pull/32386) and tells the compiler to optimize for size rather than performance. @@ -1326,15 +1326,15 @@ __Jemalloc__ Rust uses jemalloc as the default allocator, which adds some size to compiled Rust binaries. Jemalloc is chosen because it is a consistent, quality allocator that has preferable performance characteristics compared to a number of common system-provided allocators. There is work being done to [make it easier to use custom allocators](https://github.com/rust-lang/rust/issues/32838), but that work is not yet finished. -__Link-time optimization__ +__链接时优化__ Rust does not do link-time optimization by default, but can be instructed to do so. This increases the amount of optimization that the Rust compiler can potentially do, and can have a small effect on binary size. This effect is likely larger in combination with the previously mentioned size optimizing mode. -__Standard library__ +__标准库__ The Rust standard library includes libbacktrace and libunwind, which may be undesirable in some programs. Using `#![no_std]` can thus result in smaller binaries, but will also usually result in substantial changes to the sort of Rust code you're writing. Note that using Rust without the standard library is often functionally closer to the equivalent C code. -As an example, the following C program reads in a name and says "hello" to the person with that name. +作为一个例子,下列 C 程序读入一个名称,并向该名称的人说“Hello”。 ```c #include @@ -1348,7 +1348,7 @@ int main(void) { } ``` -Rewriting this in Rust, you may get something like the following: +将这用 Rust 重写,您可能得到这样的内容: ```rust use std::io; @@ -1396,7 +1396,7 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize { Which should indeed roughly match C in memory usage, at the expense of more programmer complexity, and a lack of static guarantees usually provided by Rust (avoided here with the use of `unsafe`).

-Why does Rust not have a stable ABI like C does, and why do I have to annotate things with extern? +为什么 Rust 没有像 C 一样稳定的 ABI,以及为什么必须用 extern 来标注?

Committing to an ABI is a big decision that can limit potentially advantageous language changes in the future. Given that Rust only hit 1.0 in May of 2015, it is still too early to make a commitment as big as a stable ABI. This does not mean that one won't happen in the future, though. (Though C++ has managed to go for many years without specifying a stable ABI.) @@ -1404,19 +1404,19 @@ Committing to an ABI is a big decision that can limit potentially advantageous l The `extern` keyword allows Rust to use specific ABI's, such as the well-defined C ABI, for interop with other languages.

-Can Rust code call C code? +Rust 代码能调用 C 代码吗?

-Yes. Calling C code from Rust is designed to be as efficient as calling C code from C++. +可以。从 Rust 调用 C 代码与从 C++ 调用 C 代码一样高效。

-Can C code call Rust code? +C 代码能调用 Rust 代码吗?

-Yes. The Rust code has to be exposed via an `extern` declaration, which makes it C-ABI compatible. Such a function can be passed to C code as a function pointer or, if given the `#[no_mangle]` attribute to disable symbol mangling, can be called directly from C code. +可以。The Rust code has to be exposed via an `extern` declaration, which makes it C-ABI compatible. Such a function can be passed to C code as a function pointer or, if given the `#[no_mangle]` attribute to disable symbol mangling, can be called directly from C code.

-I already write perfect C++. What does Rust give me? +我已经写了完美的 C++。 Rust 能给我什么?

Modern C++ includes many features that make writing safe and correct code less error-prone, but it's not perfect, and it's still easy to introduce unsafety. This is something the C++ core developers are working to overcome, but C++ is limited by a long history that predates a lot of the ideas they are now trying to implement. @@ -1424,13 +1424,13 @@ Modern C++ includes many features that make writing safe and correct code less e Rust was designed from day one to be a safe systems programming language, which means it's not limited by historic design decisions that make getting safety right in C++ so complicated. In C++, safety is achieved by careful personal discipline, and is very easy to get wrong. In Rust, safety is the default. It gives you the ability to work in a team that includes people less perfect than you are, without having to spend your time double-checking their code for safety bugs.

-How do I do the equivalent of C++ template specialization in Rust? +如何在 Rust 中做到 C++ 模板专业化 那样?

-Rust doesn't currently have an exact equivalent to template specialization, but it is [being worked on](https://github.com/rust-lang/rfcs/pull/1210) and will hopefully be added soon. However, similar effects can be achieved via [associated types](https://doc.rust-lang.org/stable/book/associated-types.html). +Rust 目前还没有完全等同的模板专业化,这[正在研究](https://github.com/rust-lang/rfcs/pull/1210)并有希望尽快加入。不过,可以用[关联类型](https://doc.rust-lang.org/stable/book/associated-types.html)达成类似的效果。

-How does Rust's ownership system relate to move semantics in C++? +Rust 的所有权系统如何与 C++ 中的语义相关联?

The underlying concepts are similar, but the two systems work very @@ -1478,7 +1478,7 @@ void caller() { } ``` -C++ compilers are not obligated to track moves. For example, the code +C++ 编译器 are not obligated to track moves. For example, the code above compiles without a warning or error, at least using the default settings on clang. Moreover, in C++ ownership of the string `s` itself (if not its internal buffer) remains with `caller`, and so the @@ -1487,16 +1487,16 @@ been moved (in Rust, in contrast, moved values are dropped only by their new owners).

-How can I interoperate with C++ from Rust, or with Rust from C++? +如何让 Rust 与 C++ 互操作,反之亦然?

-Rust and C++ can interoperate through C. Both Rust and C++ provide a [foreign function interface](https://doc.rust-lang.org/book/ffi.html) for C, and can use that to communicate between each other. If writing C bindings is too tedious, you can always use [rust-bindgen](https://github.com/crabtw/rust-bindgen) to help automatically generate workable C bindings. +Rust 与 C++ 可以通过 C 互操作。Rust 和 C++ 都提供一个适用于 C 的[外部函数接口](https://doc.rust-lang.org/book/ffi.html),我们可以用它来相互沟通。如果编写 C 语言的绑定太麻烦,您随时可以用 [rust-bindgen](https://github.com/crabtw/rust-bindgen) 来帮忙自动生成可执行的 C 绑定。

-Does Rust have C++-style constructors? +Rust 有 C++ 风格的构造函数吗?

-No. Functions serve the same purpose as constructors without adding language complexity. The usual name for the constructor-equivalent function in Rust is `new()`, although this is just a convention rather than a language rule. The `new()` function in fact is just like any other function. An example of it looks like so: +没有。Functions serve the same purpose as constructors without adding language complexity. The usual name for the constructor-equivalent function in Rust is `new()`, although this is just a convention rather than a language rule. The `new()` function in fact is just like any other function. An example of it looks like so: ```rust struct Foo { @@ -1517,22 +1517,22 @@ impl Foo { ```

-Does Rust have copy constructors? +Rust 有复制构造函数吗?

-Not exactly. Types which implement `Copy` will do a standard C-like "shallow copy" with no extra work (similar to "plain old data" in C++). It is impossible to implement `Copy` types that require custom copy behavior. Instead, in Rust "copy constructors" are created by implementing the `Clone` trait, and explicitly calling the `clone` method. Making user-defined copy operators explicit surfaces the underlying complexity, making it easier for the developer to identify potentially expensive operations. +不太完全。Types which implement `Copy` will do a standard C-like "shallow copy" with no extra work (similar to "plain old data" in C++). It is impossible to implement `Copy` types that require custom copy behavior. Instead, in Rust "copy constructors" are created by implementing the `Clone` trait, and explicitly calling the `clone` method. Making user-defined copy operators explicit surfaces the underlying complexity, making it easier for the developer to identify potentially expensive operations.

-Does Rust have move constructors? +Rust 有移动构造函数吗?

-No. Values of all types are moved via `memcpy`. This makes writing generic unsafe code much simpler since assignment, passing and returning are known to never have a side effect like unwinding. +没有。Values of all types are moved via `memcpy`. This makes writing generic unsafe code much simpler since assignment, passing and returning are known to never have a side effect like unwinding.

-How are Go and Rust similar, and how are they different? +Go 与 Rust 有何相似,及它们有什么不同?

-Rust and Go have substantially different design goals. The following differences are not the only ones (which are too numerous to list), but are a few of the more important ones: +Rust 与 Go 有着完全不同的设计目标。下列差异不是全部的差异(它们太多而无法列出),而是较重要的一些: - Rust is lower level than Go. For example, Rust does not require a garbage collector, whereas Go does. In general, Rust affords a level of control that is comparable to C or C++. - Rust's focus is on ensuring safety and efficiency while also providing high-level affordances, while Go's is on being a small, simple language which compiles quickly and can work nicely with a variety of tools. @@ -1540,7 +1540,7 @@ Rust and Go have substantially different design goals. The following differences - Rust has strong influences from the world of functional programming, including a type system which draws from Haskell's typeclasses. Go has a simpler type system, using interfaces for basic generic programming.

-How do Rust traits compare to Haskell typeclasses? +Rust 特征与 Haskell 类型类相较如何?

Rust traits are similar to Haskell typeclasses, but are currently not as powerful, as Rust cannot express higher-kinded types. Rust's associated types are equivalent to Haskell type families. @@ -1553,24 +1553,24 @@ Some specific difference between Haskell typeclasses and Rust traits include: - Rust's `impl` resolution considers the relevant `where` clauses and trait bounds when deciding whether two `impl`s overlap, or choosing between potential `impl`s. Haskell only considers the constraints in the `instance` declaration, disregarding any constraints provided elsewhere. - A subset of Rust's traits (the ["object safe"](https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md) ones) can be used for dynamic dispatch via trait objects. The same feature is available in Haskell via GHC's `ExistentialQuantification`. -

Documentation

+

文档

-Why are so many Rust answers on Stack Overflow wrong? +为什么 Stack Overflow(问答网站)上的许多 Rust 回答是错的?

-The Rust language has been around for a number of years, and only reached version 1.0 in May of 2015. In the time before then the language changed significantly, and a number of Stack Overflow answers were given at the time of older versions of the language. +Rust 语言已存在多年,而它在 2015 年 5 月才达成 1.0 版本。在那达成之前,语言曾经发生过很多变化,而问答网站上的答案可能只适用较旧的语言版本。 -Over time more and more answers will be offered for the current version, thus improving this issue as the proportion of out-of-date answers is reduced. +随着时间的推移,会有越来越多的答案适用于当前版本,从而改善这一问题。

-Where do I report issues in the Rust documentation? +我该在哪报告 Rust 文档的问题?

-You can report issues in the Rust documentation on the Rust compiler [issue tracker](https://github.com/rust-lang/rust/issues). Make sure to read the [contributing guidelines](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#writing-documentation) first. +您可以在 Rust 编译器的[问题跟踪器](https://github.com/rust-lang/rust/issues)中报告 Rust 文档的问题。在报告前,请先阅读[贡献指南](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#writing-documentation)。

-How do I view rustdoc documentation for a library my project depends on? +如何查看我的项目所依赖的库的 rustdoc 文档?

When you use `cargo doc` to generate documentation for your own project, it also generates docs for the active dependency versions. These are put into the `target/doc` directory of your project. Use `cargo doc --open` to open the docs after building them, or just open up `target/doc/index.html` yourself. diff --git a/zh-CN/friends.html b/zh-CN/friends.html index a9c6f91dd..b3cbb5b06 100644 --- a/zh-CN/friends.html +++ b/zh-CN/friends.html @@ -1,6 +1,338 @@ --- layout: zh-CN/basic title: Rust 之友 · Rust 程序设计语言 + +localized-teams: +- + name: 1aim + url: https://1aim.com/ + logo: 1aim.svg + how: "现代、安全、通用的访问管理。" +- + name: 360dialog + url: http://www.360dialog.com + logo: 360dialog.png + how: "我们大多数的“服务消费者”都是采用 Rust 编写。" +- + name: 3DR + url: https://3dr.com/ + logo: 3dr.svg + how: "用 Rust 处理由 USB 设备到关键组件的通信,为无人机飞行和我们的移动应用服务。" +- + name: Academia.edu + url: https://www.academia.edu/ + logo: academia.edu.svg + how: "将字符串转换成结构化纸张和作者数据,比 Ruby 更快。" +- + name: AgilData + url: http://www.agildata.com/ + logo: agildata.svg + how: "MySQL 封包捕获工具。" +- + name: Algorithmia + url: https://algorithmia.com/ + logo: algorithmia.png + how: "Rust 算法开发是我们平台的一等大事。" +- + name: ANIXE + url: http://www.anixe.pl/ + logo: anixe.png + how: "用 Rust 建立下一代旅游服务交易平台。" +- + name: AppSignal + url: https://appsignal.com/ + logo: appsignal.png + how: "快速、强大的 Web 应用监控代理。" +- + name: Ather Energy + url: https://www.atherenergy.com/ + logo: ather.svg + how: "可靠地向云端发送摩托车数据。" +- + name: Autumn + url: http://autumnai.com + logo: autumn.png + how: "用 Rust 编写的机器学习。" +- + name: Beget + url: https://beget.com + logo: beget.png + how: "作为备份、资源管理系统和 DDOS 缓解措施 的一部分" +- + name: Braintree + url: https://www.braintreepayments.com/ + logo: braintree.png + how: "加速批量处理和小型命令行实用程序。" +- + name: Calyptech + url: http://calyptech.com + logo: calyptech.png + how: "用于高性能嵌入式系统组件,作为 C 的替代品。" +- + name: Cambridge Consultants + url: http://www.cambridgeconsultants.com/ + logo: cambridge-consultants.png + how: "我们正在面向我们客户的项目上编写和输送 Rust 代码。。" +- + name: Canonical + url: http://www.canonical.com + logo: canonical.svg + how: "从服务器监控到中间件的一切!" +- + name: Ceph + url: http://ceph.com + logo: ceph.png + how: "面向 librbd 的 Rust 绑定,它是一个传入 Ceph存储平台的接口。" +- + name: Chef + url: https://www.chef.io/ + logo: chef.svg + how: "Chef 让您可以开发、部署和管理基础架构、运行时环境和应用程序。" +- + name: Clever Cloud + url: https://www.clever-cloud.com/ + logo: clever-cloud.svg + how: "We 托管 Rust web 应用程序,并且我们的部分基础设施也是使用 Rust 开发。" +- + name: CodePicnic + url: https://codepicnic.com + logo: codepicnic.png + how: "我们提供 Rust 沙箱,人们可以用它来学习,以及复刻(Fork)、扩展所想的示例或应用程序。" +- + name: Coursera + url: https://www.coursera.org + logo: coursera.png + how: "安全的 Docker 容器 中的 编程分配。" +- + name: Coredump Hackerspace + url: https://www.coredump.ch/ + logo: coredump.png + how: "我们开发了 CLI 工具、游戏和和我们的后端基础架构,以及组织事件" +- + name: Coturnix + url: http://www.coturnix.fr/ + logo: coturnix.png + how: "用机器学习和优化最大限度地减少建筑物的能源消耗。" +- + name: craft ai + url: http://craft.ai + logo: craftai.png + how: "我们的核心机器学习引擎采用 Rust 编写。" +- + name: Dazta + url: https://www.dazta.com + logo: dazta.svg + how: "用 Rust 建立智能金融产品。" +- + name: Delimiter + url: https://www.delimiter.com/ + logo: delimiter.png + how: "Rust 为我们的裸机配置系统提供动力。" +- + name: Dropbox + url: https://www.dropbox.com + logo: dropbox.svg + how: "优化云文件存储。" +- + name: ETCDEV Team + url: https://www.etcdevteam.com/ + logo: etcface.png + how: "ETCDEV Team 是一批专业的软件工程师,全职工作于 Ethereum Classic 核心项目。" +- + name: Ethcore + url: https://ethcore.io + logo: ethcore.png + how: "为 Ethereum 革命提供动力。" +- + name: Everlane + url: http://www.everlane.com/ + logo: everlane.png + how: "可靠的高性能指标聚合和转发。" +- + name: Faraday + url: http://faraday.io + logo: faraday.svg + how: "安全传输凭据。" +- + name: GiGa infosystems GmbH + url: https://www.giga-infosystems.com + logo: giga.svg + how: "Rust 是我们重写数据库以用于 3D 地质模型数据库的主要工具。" +- + name: Gremlin Inc + url: https://www.gremlininc.com + logo: gremlininc.svg + how: "安全、有效地促成受控制的混沌。" +- + name: Habitat + url: https://www.habitat.sh + logo: habitat.svg + how: "Habitat 是一个应用自动化框架。" +- + name: Honeypot + url: https://www.honeypot.io/ + logo: honeypot.svg + how: "We 建立并使用 Searchspot,这是一种基于 Elasticsearch 的搜索引擎。招聘人员使用它来搜索正在寻找的开发人员。" +- + name: krypt.co + url: https://krypt.co + logo: krypt.co.png + how: "在 iOS 与 Android 之间共享用于 SSH 主机签名验证的代码,以及一个 PKCS11 共享库。" +- + name: LINE + url: https://line.me/ + logo: line.png + how: "用于配置助手。" +- + name: Linkerd + url: https://linkerd.io/ + logo: linkerd.svg + how: "我们使用 Rust 来扩展 Linkerd 服务网格,一个轻量级的 TCP/TLS 负载平衡器。" +- + name: Linki Tools + url: http://linki.tools/ + logo: linkitools.png + how: "用于测试和验证的工具链。" +- + name: MaidSafe + url: http://www.maidsafe.net + logo: maidsafe.svg + how: "建立一个分布式的数据和通信网络。" +- + name: Mozilla + url: https://www.mozilla.org + logo: mozilla.png + how: "建立 Servo 浏览器引擎,集成到 Firefox,以及其他项目。" +- + name: Navitia + url: http://www.navitia.io + logo: navitia.svg + how: "基于 Elasticsearch 建立的地理编码服务。" +- + name: npm, Inc + url: http://www.npmjs.com + logo: npm.svg + how: "代替 C 语言并重写注册表服务架构中的性能关键瓶颈。" +- + name: OneSignal + url: https://onesignal.com + logo: onesignal.svg + how: "大容量、跨平台的推送通知投递。" +- + name: OVH + url: https://www.ovh.com + logo: ovh.png + how: "我们用 Rust 来构建高性能、高可用性的日志管理系统。" +- + name: Postmates + url: https://postmates.com/ + logo: postmates.png + how: "Rust 正在 Infrastructure 团队编写系统守护进程的过程中孵化。" +- + name: PingCAP + url: https://github.com/pingcap/tikv + logo: pingcap.png + how: "使用 Rust 和 Raft 建立分布式键值存储。" +- + name: PurchaseClinic.com + url: http://purchaseclinic.com/ + logo: purchaseclinic.com.png + how: "我们的后端(REST API)是一个 100% 的 Rust 服务器,基于 Iron。" +- + name: Sandstorm + url: https://sandstorm.io + logo: sandstorm-logo-rust.svg + how: "我们的 Collections 应用的后端采用 Rust 编写。" +- + name: Sentry + url: https://www.getsentry.com/ + logo: sentry-horizontal-black.svg + how: "一个 Sentry API 的命令行客户端。" +- + name: slowtec + url: http://www.slowtec.de/ + logo: slowtec.svg + how: "我们强大、可靠的自动化系统完全采用 Rust 编写。" +- + name: SmartThings + url: http://www.smartthings.com/ + logo: smartthings.png + how: "我们的 SmartThings Hub 中有了内存安全的嵌入式应用程序,并支持在云中提供服务。" +- + name: Snips + url: https://snips.ai/ + logo: snips.svg + how: "AI assistants that are private by design." +- + name: Spoqa + url: https://www.spoqa.com/ + logo: spoqa.png + how: "我们的 POS 集成 SDK 完全用 Rust 编写。" +- + name: Stratum Security + url: https://stratumsecurity.com/ + logo: stratum.png + how: "数据渗透测试和应用安全。" +- + name: superscale networks + url: https://www.superscale.io/ + logo: superscale.svg + how: "我们在成千上万的 4-16Mb RAM 的 Linux 路由器上运行 rust-mips。Rust 是唯一的有足够运行约束的现代语言,使之成为可能。" +- + name: Telenor Digital + url: https://www.telenordigital.com/ + logo: telenordigital.png + how: "提高并发 Webhook 投递服务的性能和可靠性。" +- + name: Tessel + url: https://www.tessel.io + logo: tessel.svg + how: "支持 Rust 应用的单板计算平台。" +- + name: thoughtram + url: http://thoughtram.io + logo: thoughtram.png + how: "我们的训练平台 classroom.thoughtram.io 的后端采用 nickel.rs,100% 的 Rust" +- + name: ThreatX + url: https://threat-x.com/ + logo: threatx.svg + how: "Threat X Web 应用防火墙(WAF)和中央分析引擎采用 Rust 编写,促进高带宽 Web 应用程序的实时分析。" +- + name: Tilde + url: http://www.tilde.io + logo: tilde.png + how: "优化 Skylight,Rails 分析器。" +- + name: TrafficLand + url: http://www.trafficland.com/ + logo: trafficland.svg + how: "视频转码、操作和分析。" +- + name: Wire + url: https://wire.com + logo: wire.svg + how: "Wire 的 Axolotl 协议实现和其他密码学及实用工具库采用 Rust 开发,然后为 iOS 和 Android 交叉编译。" +- + name: Xero + url: https://www.xero.com + logo: xero.png + how: "美观的会计软件的基础设施。" +- + name: AdHawk + url: https://www.tryadhawk.com + logo: adhawk.png + how: "我们使用 Rust 解析我们所有的 User-Agent 头。" +- + name: TreeScale + url: https://www.treescale.com + logo: treescale.png + how: "在 TreeScale,我们使用 Rust 和 MIO 实现了分布式的 PubSub 系统,这为我们提供了8倍的性能来处理和分发容器映像" +- + name: EVO.company + url: https://evo.company + logo: evo.company.svg + how: "我们有用 Rust 编写的 开发工具、集装箱化、监控和业务流程系统。" ---
diff --git a/zh-CN/index.html b/zh-CN/index.html index 21cbf1d6a..09f7b3ec6 100644 --- a/zh-CN/index.html +++ b/zh-CN/index.html @@ -7,7 +7,7 @@

Rust 是一种系统编程语言。 - 它具有惊人的运行速度,能够防止程序错误,并保证了线程安全。 + 它有着惊人的运行速度,能够防止段错误,并保证线程安全。
看看谁在使用 Rust

@@ -24,15 +24,15 @@

特点

    -
  • 零开销的抽象
  • +
  • 零开销抽象
  • 转移语义
  • 保证内存安全
  • -
  • 没有数据竞争的线程
  • +
  • 线程无数据竞争
  • trait 泛型
  • 模式匹配
  • 类型推断
  • 极小运行时
  • -
  • 高效的C绑定
  • +
  • 高效C绑定
diff --git a/zh-CN/legal.md b/zh-CN/legal.md index 24b22d0b1..55c2a702b 100644 --- a/zh-CN/legal.md +++ b/zh-CN/legal.md @@ -1,20 +1,20 @@ --- layout: zh-CN/default -title: Rust Legal Policies · Rust 程序设计语言 +title: Rust 法律政策 · Rust 程序设计语言 --- -# Copyright +# 版权 -## Code +## 代码 -Rust's [code](https://github.com/rust-lang/rust) is primarily distributed under -the terms of both the MIT license and the Apache License (Version 2.0), with -portions covered by various BSD-like licenses. -See [LICENSE-APACHE](https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE), -[LICENSE-MIT](https://github.com/rust-lang/rust/blob/master/LICENSE-MIT), -and [COPYRIGHT](https://github.com/rust-lang/rust/blob/master/COPYRIGHT) for details. +Rust 的[代码](https://github.com/rust-lang/rust)主要以 + MIT 许可证和 Apache 许可证(版本 2.0)的条款分发, +部分也受各种类 BSD 许可证覆盖。 +参阅 [LICENSE-APACHE](https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE)、 +[LICENSE-MIT](https://github.com/rust-lang/rust/blob/master/LICENSE-MIT) 和 +[COPYRIGHT](https://github.com/rust-lang/rust/blob/master/COPYRIGHT) 了解详细信息。 -## Art +## 艺术 The Rust and Cargo logos (bitmap and vector) are owned by Mozilla and distributed under the terms of the @@ -42,7 +42,7 @@ Variants of the Rust logo can be found at: * [rust-logo-64x64.png](/logos/rust-logo-64x64.png) * [rust-logo-blk.svg](/logos/rust-logo-blk.svg) -# Trademark policy +# 商标政策 The Rust and Cargo names and brands make it possible to say what is officially part of the Rust community, and what isn't. So we're careful about where we @@ -57,7 +57,7 @@ allowed and do not require permission; most commercial uses require permission. In either case, the most important rule is that uses of the trademarks cannot appear official or imply any endorsement by the Rust project. -## The Rust trademarks +## Rust 商标 The Rust programming language is an open source, community project governed by a core team. It is also sponsored by the Mozilla Foundation ("Mozilla"), which @@ -86,7 +86,7 @@ know they're getting the product produced by the Rust project and not someone else's modified version. The trademark assures users and developers of the quality and safety of the product they're using. -## Using the trademarks +## 使用商标 ### Appearing official, affiliated, or endorsed @@ -115,7 +115,7 @@ They may not be used: - in ways that confuse the community as to whether the Rust programming language is open source and free to use. -### Uses that do not require explicit approval +### 不需要明确批准的用途 There are a variety of uses that do not require explicit approval. **However, in all of the cases outlined below, you must ensure that use of the Rust trademarks does not appear official, as explained above.** @@ -151,7 +151,7 @@ above uses, the **event cannot appear to be officially endorsed or run by the Ru papers, books, and product packaging to refer to the Rust programming language or the Rust project is allowed. -### Uses that require explicit approval +### 需要明确批准的用途 * Distributing a modified version of the Rust programming language or the Cargo package manager and calling it Rust or Cargo requires explicit, written @@ -165,34 +165,29 @@ long as (1) it is clearly communicated that the merchandise is not in any way an official part of the Rust project and (2) it is clearly communicated whether profits benefit the Rust project. -* Using the Rust trademarks within another trademark requires written permission -from the Rust core team except as described above. +* 除上述事例外,在其他商标中使用 Rust 商标需要 Rust 核心团队的书面许可。 -## Notes +## 备注 -If you have any doubts about whether your intended use of a Rust Trademark -requires permission, please contact us at +如果您就 Rust 商标的使用许可存有任何疑问,请与我们联系: [trademark@rust-lang.org](mailto:trademark@rust-lang.org). -This document was derived in part from the -[Python Software Foundation Trademark Usage Policy](https://www.python.org/psf/trademarks/). +本文档部分取自 +[Python 软件基金会商标使用政策](https://www.python.org/psf/trademarks/)。 -This document is not an official statement of Mozilla trademark policy, but -serves to clarify Mozilla's trademark policy as it relates to Rust. +本文件不是 Mozilla 商标政策的官方声明,而是用于澄清 Mozilla 就 Rust 相关的商标政策。 -## Helping Out +## 帮助我们 -As a member of the Rust community, please keep an eye out for questionable uses -of the Rust logo and "Rust" word mark. You can report potential misuse to -[trademark@rust-lang.org](mailto:trademark@rust-lang.org). We will evaluate each case -and take appropriate action. +作为 Rust 社区的成员,请留意用途成疑的 +Rust 标志和“Rust”字样。您可以将潜在的滥用报告到 +[trademark@rust-lang.org](mailto:trademark@rust-lang.org)。我们将评估每个事例并采取适当的行动。 -Please do not approach users of the trademarks with a complaint. That should be -left to Mozilla and its representatives. +请不要接触被投诉的商标使用人。这应该留给 Mozilla 及其代表处理。 -Thanks! +诚挚感谢! -## License +## 许可证 -Interested parties may adapt this document freely under the -[Creative Commons CC0 license](https://creativecommons.org/publicdomain/zero/1.0/). +有意者可以 +[创作共用 CC0 许可证](https://creativecommons.org/publicdomain/zero/1.0/) 自由调整本文档。 diff --git a/zh-CN/other-installers.md b/zh-CN/other-installers.md index 4fad95f40..6dfb08908 100644 --- a/zh-CN/other-installers.md +++ b/zh-CN/other-installers.md @@ -13,40 +13,31 @@ title: 其他安装方法 · Rust 程序设计语言 ## 您应该使用哪个安装程序? -Rust 在许多平台上运行,并且有很多方法来安装 Rust 。 -如果您想要安装 Rust 最简单,推荐的方法, -然后参照主要的[安装页面][installation page]上的说明。 - -That page describes installation via [`rustup`], a tool that manages multiple -Rust toolchains in a consistent way across all platforms Rust supports. Why -might one _not_ want to install using those instructions? - -- Offline installation. `rustup` downloads components from the internet on - demand. If you need to install Rust without access to the internet, `rustup` - is not suitable. -- Preference for the system package manager. On Linux in particular, but also on - macOS with [Homebrew], and Windows with [Chocolatey], developers sometimes - prefer to install Rust with their platform's package manager. -- Preference against `curl | sh`. On Unix, we usually install `rustup` by - running a shell script via `curl`. Some have concerns about the security of - this arrangement and would prefer to download and run the installer - themselves. -- Validating signatures. Although `rustup` performs its downloads over HTTPS, - the only way to verify the signatures of Rust installers today is to do so - manually with the standalone installers. -- GUI installation and integration with "Add/Remove Programs" on - Windows. `rustup` runs in the console and does not register its installation - like typical Windows programs. If you prefer a more typical GUI installation - on Windows there are standalone `.msi` installers. In the future - `rustup` will also have a GUI installer on Windows. - -Rust's platform support is defined in [three tiers], which correspond closely -with the installation methods available: in general, the Rust project provides -binary builds for all tier 1 and tier 2 platforms, and they are all installable -via `rustup`. Some tier 2 platforms though have only the standard library -available, not the compiler itself; that is, they are cross-compilation targets -only; Rust code can run on those platforms, but they do not run the compiler -itself. Such targets can be installed with the `rustup target add` command. +Rust 能在许多平台上运行,并且有多种方法来安装 Rust。 +如果您想要安装 Rust 最简单、最推荐的方法, +请参照主要[安装页面][installation page]上的操作说明。 + +本页面会介绍通过 [`rustup`] 安装,它是一个管理多个 +Rust 工具链的工具,从而为多个平台提供一致的 Rust 支持。 +您还想试试其他的安装方式?见下文。 + +- 官方安装程序。`rustup` 按需从互联网下载组件。如果您需要离线安装 Rust,那么 `rustup` + 并不合适。 +- 系统的软件包管理器。在 Linux 上尤为如此,不过 + macOS 上也有 [Homebrew],Windows 也有 [Chocolatey], + 开发者有时喜欢用他们平台的软件包管理器来安装 Rust。 +- `curl | sh`。在 Unix 上,我们通常通过 `curl` 运行一个 shell 脚本来安装 `rustup`。有些人可能担心这样做的安全性,而更愿意手动下载和运行安装程序。 +- 验证签名。尽管 `rustup` 通过 HTTPS 完成下载,但目前验证 Rust 安装程序的签名的唯一方式是手动验证独立安装包。 +- Windows 上的图形化“添加/删除程序”。`rustup` 在控制台中运行,并且不像典型的 Windows 程序那样注册其安装。如果您偏好典型的 GUI 安装,我们有独立的 `.msi` 安装包。在未来, + `rustup` 也将有 Windows 上的 GUI 安装程序。 + +Rust 的平台支持定义共有[三层],这与可用的安装方法密切相关: +通常来说,Rust 项目 +为所有一级和二级平台提供二进制版本,并且它们可 +通过 `rustup` 安装。部分二级平台只有标准库可用, +而没有编译器,即它们只是交叉编译的目标; +Rust 代码可以在这些平台上运行,但并不在这些平台上运行编译器。 +此类目标可以用 `rustup target add` 命令来安装。 ## 安装 `rustup` 的其他方法 @@ -92,24 +83,18 @@ curl https://sh.rustup.rs -sSf | sh -s -- --help ## 独立安装程序 -The official Rust standalone installers contain a single release of Rust, and -are suitable for offline installation. They come in three forms: tarballs -(extension `.tar.gz`), that work in any Unix-like environment, Windows -installers (`.msi`), and Mac installers (`.pkg`). These installers come with -`rustc`, `cargo`, `rustdoc`, the standard library, and the standard -documentation, but do not provide access to additional cross-targets like -`rustup` does. +官方的 Rust 独立安装程序其中包含一个 Rust 发布版本,它适合离线安装。它们也有三种形式:适用于任何类 Unix 环境的 tarballs(扩展名 `.tar.gz`), Windows 安装包(`.msi`),以及 Mac 安装包(`.pkg`)。这些安装程序附有 +`rustc`、`cargo`、`rustdoc`、标准库,以及标准文档,但不提供 `rustup` 那样的其他跨目标访问。 使用独立安装程序的最常见原因是: - 离线安装 - 热衷在 Windows 上使用更多平台集成的图形安装程序 -Each of these binaries is signed with the [Rust signing key], which is -[available on keybase.io], by the Rust build infrastructure, with -[GPG]. In the tables below, the `.asc` files are the signatures. +这些二进制文件每个均使用了 [Rust signing key]来签名(由 Rust 构建基础设施使用 [GPG]),该密钥也在 +[keybase.io] 上提供。在下面的表格中,`.asc` 文件即该签名。 -Past releases can be found in [the archives]. +过去发布的版本可在[此处存档]中找到。 {% for channel in site.channels %} diff --git a/zh-CN/security.html b/zh-CN/security.html index 5831460ee..e9c233fc5 100644 --- a/zh-CN/security.html +++ b/zh-CN/security.html @@ -1,99 +1,92 @@ --- layout: zh-CN/default -title: Rust Security Policy · Rust 程序设计语言 +title: Rust 安全政策 · Rust 程序设计语言 --- -

Rust Security Policy

+

Rust 安全政策

-

Reporting a Bug

+

报告 Bug

-

Safety is one of the core principles of Rust, and to that end, we would -like to ensure that Rust has a secure implementation. Thank you for taking the -time to responsibly disclose any issues you find.

+

安全是 Rust 的核心原则之一,为此目的, +我们尽力确保 Rust 有一个安全的实现。 +感谢您花费时间来负责任地披露您发现的任何问题。

-

All security bugs in the Rust distribution should be reported by email to -security@rust-lang.org. This list -is delivered to a small security team. Your email will be acknowledged within 24 -hours, and you'll receive a more detailed response to your email within 48 -hours indicating the next steps in handling your report. If you would like, you -can encrypt your report using our public key. -This key is also On -MIT's keyserver and reproduced below. +

Rust 分发版本中的所有安全漏洞都应通过电子邮件报告至 +security@rust-lang.org。 +此列表被交付给一个小型的安全团队。您的电子邮件将在24小时内被确认妥收, +并将在48小时内收到更详细的回复通知处理报告的后续步骤。如果您愿意,您可以 +使用我们的公钥加密您的报告。 +此密钥也被放在 +MIT 的密钥服务器本页末尾。 -

This email address receives a large amount of spam, so be sure to use a -descriptive subject line to avoid having your report be missed. After the -initial reply to your report, the security team will endeavor to keep you -informed of the progress being made towards a fix and full announcement. As -recommended by RFPolicy, -these updates will be sent at least every five days. In reality, this is more -likely to be every 24-48 hours.

+

此电子邮件地址有收到大量垃圾邮件,因此请一定在主题行撰写有意义的描述,以免错过您的报告。 +在初步回复您的报告后,安全团队将尽力保证您了解修复与全面公布方面取得的进展。 +按 RFPolicy 所推荐, +这些更新将会至少每 5 天发送一次。现实情况中,还可能 +每 24-48 小时发送一次。

-

If you have not received a reply to your email within 48 hours, or have not -heard from the security team for the past five days, there are a few steps you -can take:

+

如果您没有在48小时内收到您的电子邮件的回复,或者 +过去五天都没有听到安全小组的音信, +还有几个步骤可以采取:

-

Please note that the discussion forums and #rust-internals IRC channel are -public areas. When escalating in these venues, please do not discuss your -issue. Simply say that you're trying to get a hold of someone from the security +

请注意,论坛和 #rust-internals IRC 频道为公共区域。 +在这些场地寻求联络人时,不要讨论你的问题。 +只需简单地说,你正在找一个负责安全方面的联系人。 team.

-

Disclosure Policy

+

披露政策

-

The Rust project has a 5 step disclosure process.

+

Rust 项目的披露流程有5个步骤。

    -
  1. The security report is received and is assigned a primary handler. This -person will coordinate the fix and release process.
  2. +
  3. 收到安全报告,分配一个主导处理人。他将负责协调修复和发布流程。
  4. -
  5. The problem is confirmed and a list of all affected versions is determined.
  6. +
  7. 确认问题并确定所有受影响版本的列表。
  8. -
  9. Code is audited to find any potential similar problems.
  10. +
  11. 审计代码以发现任何潜在的类似问题。
  12. -
  13. Fixes are prepared for all releases which are still under maintenance. -These fixes are not committed to the public repository but rather held locally -pending the announcement.
  14. +
  15. 为所有仍在维护的版本准备修补程序。 +这些修补程序不会提交到公共代码库,而是放在本地 +等待公告。
  16. -
  17. On the embargo date, the -Rust security mailing list is sent a copy of the announcement. The changes -are pushed to the public repository and new builds are deployed to -rust-lang.org. Within 6 hours of the mailing list being notified, a copy of -the advisory will be published on the Rust blog.
+
  • 在 embargo 日期, +Rust 安全邮件列表 发布公告的副本。变更 +被推送到公共代码库并将新的构建版本部署到 +rust-lang.org。在邮件列表收到通知的 6 小时内,在 Rust 博客上发布通告。
  • -

    This process can take some time, especially when coordination is required -with maintainers of other projects. Every effort will be made to handle the bug -in as timely a manner as possible, however it's important that we follow the -release process above to ensure that the disclosure is handled in a consistent -manner.

    +

    此流程可能需要一些时间,特别是需要与其他项目的维护者协调时。 +我们会尽力、尽量及时地处理问题,但遵循我们上述的发布流程以确保 +一致处理披露也十分重要。

    -

    Receiving Security Updates

    +

    接收安全更新

    -

    The best way to receive all the security announcements is to subscribe to -the 接收所有安全公告的最佳方式是 +订阅 Rust -security announcements mailing list. The mailing list is very low traffic, -and it receives the public notifications the moment the embargo is lifted.

    +安全公告邮件列表。该邮件列表通讯量很少, +将在取消 embargo 时收到公开通知。

    -

    Advance notification

    +

    提前通知

    -

    We will announce vulnerabilities 72 hours before the embargo is lifted to -distros@openwall, -so that Linux distributions can update their packages.

    +

    我们将在 embargo 的 72小时之前通告漏洞至 +distros@openwall, +以便 Linux 发行版可以更新其软件包。

    -

    Comments on This Policy

    +

    评论此政策

    -

    If you have any suggestions to improve this policy, please send an email to +

    如果您有任何建议来改善此政策,请发送电子邮件至 security@rust-lang.org.

    -

    Plaintext PGP Key

    +

    纯文本 PGP Key

    {% include rust-security-team-key.gpg.ascii %}
    diff --git a/zh-CN/team.md b/zh-CN/team.md index 05bdd766a..8b788b262 100644 --- a/zh-CN/team.md +++ b/zh-CN/team.md @@ -1,6 +1,8 @@ --- layout: zh-CN/default title: Rust 团队 · Rust 程序设计语言 +extra_css: + - team.css localized-teams: Core team: @@ -14,77 +16,37 @@ localized-teams: responsibility: "Rust 标准库、Rust 语言的包及公约" Compiler team: name: 编译器开发团队 - responsibility: "compiler internals, optimizations" + responsibility: "编译器内部、优化" Tooling and infrastructure: name: 工具和基础组件团队 - responsibility: "提高工具支持 (譬如 Cargo、rustup)、CI 基础控件,等。" + responsibility: "提高工具支持(例如 Cargo、rustup)、CI 基础控件,等等。" Community team: name: 社区团队 - responsibility: "coordinating events, outreach, commercial users, teaching materials, and exposure" + responsibility: "协调活动、推广、商业用户、教材及曝光率" Documentation team: name: 文档团队 responsibility: "确保 Rust 拥有极好的文档" Moderation team: name: 审核团队 - responsibility: "helping uphold the code of conduct" + responsibility: "帮助维护行为守则" Rust team alumni: name: Rust 团队旧友 responsibility: "享受悠哉的退休生活" --- - - # Rust 团队 -Rust 的项目是由若干个团队分别 -[管辖](https://github.com/rust-lang/rfcs/blob/master/text/1068-rust-governance.md), -的每个团队只关注特定的内容,以下是团队人名单(姓氏字母排序)。 +Rust 的项目是由若干个团队分别[管辖](https://github.com/rust-lang/rfcs/blob/master/text/1068-rust-governance.md), +每个团队只关注特定的内容,以下是团队人员名单(按姓氏字母排序)。 -To contact a team, post your question or comment to [the Internals -forum](https://internals.rust-lang.org/) and tag your post with the category -corresponding to the team name. Note that security disclosures should follow -the [Rust security disclosure process](security.html). +要联系某个团队,请发布您的问题或评论至[内部论坛](https://internals.rust-lang.org/),并用相应团队的名称标注您的帖子。请注意,安全披露应该遵循 +[Rust 安全披露流程](security.html)。 {% for team in site.data.team.teams %}

    {{ page.localized-teams[team.name].name | default: team.name }}

    -职能: {{ page.localized-teams[team.name].responsibility | default: team.responsibility }} +职能{{ page.localized-teams[team.name].responsibility | default: team.responsibility }}
    @@ -108,7 +70,7 @@ the [Rust security disclosure process](security.html).
    irc: {% if person.irc %}{{ person.irc }}{% else %}{{ nick }}{% endif %}
    {% if person.ex-teams %} -
    团队: {% for ex-team in person.ex-teams %}{% if forloop.first == false %}, {% endif %}{{ page.localized-ex-teams[ex-team] | default: ex-team }}{% endfor %}
    +
    团队:{% for ex-team in person.ex-teams %}{% if forloop.first == false %}, {% endif %}{{ page.localized-ex-teams[ex-team] | default: ex-team }}{% endfor %}
    {% endif %}
    {{ person.name }} diff --git a/zh-CN/user-groups.md b/zh-CN/user-groups.md index ec21e2bfc..9b0a715b9 100644 --- a/zh-CN/user-groups.md +++ b/zh-CN/user-groups.md @@ -1,9 +1,9 @@ --- layout: zh-CN/default -title: Rust User Groups · Rust 程序设计语言 +title: Rust 用户群组 · Rust 程序设计语言 --- -# Rust User Groups +# Rust 用户群组 There are more than 90 Rust User Groups worldwide in over 35 countries. Rustaceans meet periodically in Rust User Groups. Its a @@ -15,7 +15,7 @@ Community Team](./team.html#Community) or even better, open a pull request against [this website](https://github.com/rust-lang/rust-www/blob/master/en-US/user-groups.md). -## Australia +## 澳大利亚 [Rust Brisbane](https://www.meetup.com/Rust-Brisbane/), Brisbane. @@ -23,19 +23,19 @@ website](https://github.com/rust-lang/rust-www/blob/master/en-US/user-groups.md) [Rust Sydney](https://www.meetup.com/Rust-Sydney/), Sydney. -## Belarus +## 白俄罗斯 [Rust in Minsk](https://www.meetup.com/Rust-%D0%B2-%D0%9C%D0%B8%D0%BD%D1%81%D0%BA%D0%B5/), Minsk. -## Belgium +## 比利时 [Belgium Rust User Group](https://www.meetup.com/Belgium-Rust-user-group/), Brussels. -## Bolivia +## 玻利维亚 [Rust Bolivia](http://www.mozillabolivia.org/rust/), Santa Cruz, Bolivia. -## Brazil +## 巴西 [Rust Floripa](https://www.meetup.com/Rust-Floripa/), Florianópolis. @@ -45,7 +45,7 @@ website](https://github.com/rust-lang/rust-www/blob/master/en-US/user-groups.md) [Rust São Paulo](https://www.meetup.com/Rust-Sao-Paulo-Meetup/), São Paulo. -## Canada +## 加拿大 [Montréal Rust Language Meetup](https://www.meetup.com/Montreal-Rust-Language-Meetup/), Montréal, QC. @@ -55,19 +55,19 @@ website](https://github.com/rust-lang/rust-www/blob/master/en-US/user-groups.md) [Vancouver Rust](https://www.meetup.com/Vancouver-Rust/), Vancouver, BC. -## Croatia +## 克罗地亚 [Lambda Zagreb](https://www.meetup.com/lambdazagreb/), Zagreb. -## Czech Republic +## 捷克 [Rust Prague](https://www.meetup.com/rust-prague/), Prague. -## Denmark +## 丹麦 [Copenhangen Rust Group](http://cph.rs), Copenhagen. -## France +## 法国 [Lille Rust Meetup](https://www.meetup.com/rust-lille/), Lille. @@ -75,11 +75,11 @@ website](https://github.com/rust-lang/rust-www/blob/master/en-US/user-groups.md) [Rust Paris](https://www.meetup.com/Rust-Paris/), Paris. -## Finland +## 芬兰 [Finland Rust-lang Group](https://www.meetup.com/Finland-Rust-Meetup/), Helsinki. -## Germany +## 德国 [Rust Cologne/Bonn User Group](https://www.meetup.com/Rust-Cologne-Bonn/), Köln. @@ -95,11 +95,11 @@ website](https://github.com/rust-lang/rust-www/blob/master/en-US/user-groups.md) [Rust Rhein-Main](https://www.meetup.com/Rust-Rhein-Main/), Frankfurt / Darmstadt. -## Hungary +## 匈牙利 [Rust Hungary Meetup](https://www.meetup.com/Rust-Hungary-Meetup/), Budapest. -## India +## 印度 [Hyderabad Rust Meetup](https://www.meetup.com/Hyderabad-Rust-Meetup/), Hyderabad.