diff --git a/ChangeLog.md b/ChangeLog.md
deleted file mode 100644
index 319a867..0000000
--- a/ChangeLog.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# ChangeLog
-
-## 2022-03-31
-
-- Add [Iterator](https://practice.rs/functional-programing/iterator.html)
-- Add [Newtype and DST](https://practice.rs/newtype-sized.html)
-
-
-## 2022-03-30
-
-- Add [Advance Liftime](https://practice.rs/lifetime/advance.html) chapter
-
-### 2022-03-29
-
-- Add language switch icon in top-right corner
-- Add [&'static and T: 'static](https://practice.rs/lifetime/static.html)
-
-
-### 2022-03-28
-
-- Add [Basic lifetime](https://practice.rs/lifetime/basic.html)
-
-### 2022-03-25
-
-- Replace gitalk with giscus comments system which is based on Github Discussions
-- Update css styles
-
-### 2022-03-24
-
-- Add [comment-docs.md(Zh)]
-
-### 2022-03-23
-
-- Add [crate.md(Zh)]
-- Add [module.md(Zh)]
-- Add [use-pub.md(Zh)]
-
-
-### 2022-03-20
-
-- Add [Result (zh)]
-- Add [Panics (Zh)]
-- Add [Type conversion - others.md (zh)]
-
-### 2022-03-18
-
-- Add [Type conversion - From and Into( Zh )]
-
-### 2022-03-17
-
-- Add [Small projects with Elegant code](https://practice.rs/elegant-code-base.html)
-
-### 2022-03-15
-
-- Add [Formatting](https://practice.rs/formatted-output/formatting.html)
-- Add [prinln! and format!](https://practice.rs/formatted-output/println.html)
-- Add [Debug and Display](https://practice.rs/formatted-output/debug-display.html)
-- Add [Comments and Docs](https://practice.rs/comments-docs.html)
-- Add [Fighting with Compiler](https://practice.rs/fight-compiler/intro.html)
-
-
-### 2022-03-14
-
-- Add [Package and Crate](https://practice.rs/crate-module/crate.html)
-- Add [Modules](https://practice.rs/crate-module/module.html)
-- Add [Advanced use and pub](https://practice.rs/crate-module/use-pub.html)
-
-### 2022-03-11
-
-- Add one exercise in [Patterns](https://practice.rs/pattern-match/patterns.html)
-- Add [Result and ?](https://practice.rs/result-panic/result.html)
-
-### 2022-03-10
-
-- Add [Type conversions - From/Into](https://practice.rs/type-conversions/from-into.html)
-- Add [Type conversions - Others](https://practice.rs/type-conversions/others.html)
-- Add [Panics](https://practice.rs/result-panic/panic.html)
-- Add exercises for [diverging functions](https://practice.rs/basic-types/functions.html#diverging-functions)
-
-### 2022-03-09
-
-- Translate several English chapters to Chinese
-- Add [Type conversions - As](https://practice.rs/type-conversions/as.html)
-
-### 2022-03-08
-
-- Add [HashMap](https://practice.rs/collections/hashmap.html)
-- Translate several English chapters to Chinese
-
-### 2022-03-07
-
-- Add [Strings](https://practice.rs/collections/string.html)
-- Add [Vectors](https://practice.rs/collections/vector.html)
-
-### 2022-03-06
-
-- Add [Advanced Traits](https://practice.rs/generics-traits/advanced-traits.html)
-
-### 2022-03-05
-
-- Add [Trati object](https://practice.rs/generics-traits/trait-object.html)
-
-### 2022-03-05
-
-- Add [Traits chapter](https://practice.rs/generics-traits/traits.html) and solutions
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index f49a4e1..aae4510 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,201 +1,395 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
+Attribution 4.0 International
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+=======================================================================
- 1. Definitions.
+Creative Commons Corporation ("Creative Commons") is not a law firm and
+does not provide legal services or legal advice. Distribution of
+Creative Commons public licenses does not create a lawyer-client or
+other relationship. Creative Commons makes its licenses and related
+information available on an "as-is" basis. Creative Commons gives no
+warranties regarding its licenses, any material licensed under their
+terms and conditions, or any related information. Creative Commons
+disclaims all liability for damages resulting from their use to the
+fullest extent possible.
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
+Using Creative Commons Public Licenses
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
+Creative Commons public licenses provide a standard set of terms and
+conditions that creators and other rights holders may use to share
+original works of authorship and other material subject to copyright
+and certain other rights specified in the public license below. The
+following considerations are for informational purposes only, are not
+exhaustive, and do not form part of our licenses.
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
+ Considerations for licensors: Our public licenses are
+ intended for use by those authorized to give the public
+ permission to use material in ways otherwise restricted by
+ copyright and certain other rights. Our licenses are
+ irrevocable. Licensors should read and understand the terms
+ and conditions of the license they choose before applying it.
+ Licensors should also secure all rights necessary before
+ applying our licenses so that the public can reuse the
+ material as expected. Licensors should clearly mark any
+ material not subject to the license. This includes other CC-
+ licensed material, or material used under an exception or
+ limitation to copyright. More considerations for licensors:
+ wiki.creativecommons.org/Considerations_for_licensors
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
+ Considerations for the public: By using one of our public
+ licenses, a licensor grants the public permission to use the
+ licensed material under specified terms and conditions. If
+ the licensor's permission is not necessary for any reason--for
+ example, because of any applicable exception or limitation to
+ copyright--then that use is not regulated by the license. Our
+ licenses grant only permissions under copyright and certain
+ other rights that a licensor has authority to grant. Use of
+ the licensed material may still be restricted for other
+ reasons, including because others have copyright or other
+ rights in the material. A licensor may make special requests,
+ such as asking that all changes be marked or described.
+ Although not required by our licenses, you are encouraged to
+ respect those requests where reasonable. More_considerations
+ for the public:
+ wiki.creativecommons.org/Considerations_for_licensees
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
+=======================================================================
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
+Creative Commons Attribution 4.0 International Public License
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
+By exercising the Licensed Rights (defined below), You accept and agree
+to be bound by the terms and conditions of this Creative Commons
+Attribution 4.0 International Public License ("Public License"). To the
+extent this Public License may be interpreted as a contract, You are
+granted the Licensed Rights in consideration of Your acceptance of
+these terms and conditions, and the Licensor grants You such rights in
+consideration of benefits the Licensor receives from making the
+Licensed Material available under these terms and conditions.
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
+Section 1 -- Definitions.
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
+ a. Adapted Material means material subject to Copyright and Similar
+ Rights that is derived from or based upon the Licensed Material
+ and in which the Licensed Material is translated, altered,
+ arranged, transformed, or otherwise modified in a manner requiring
+ permission under the Copyright and Similar Rights held by the
+ Licensor. For purposes of this Public License, where the Licensed
+ Material is a musical work, performance, or sound recording,
+ Adapted Material is always produced where the Licensed Material is
+ synched in timed relation with a moving image.
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
+ b. Adapter's License means the license You apply to Your Copyright
+ and Similar Rights in Your contributions to Adapted Material in
+ accordance with the terms and conditions of this Public License.
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
+ c. Copyright and Similar Rights means copyright and/or similar rights
+ closely related to copyright including, without limitation,
+ performance, broadcast, sound recording, and Sui Generis Database
+ Rights, without regard to how the rights are labeled or
+ categorized. For purposes of this Public License, the rights
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
+ Rights.
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
+ d. Effective Technological Measures means those measures that, in the
+ absence of proper authority, may not be circumvented under laws
+ fulfilling obligations under Article 11 of the WIPO Copyright
+ Treaty adopted on December 20, 1996, and/or similar international
+ agreements.
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
+ e. Exceptions and Limitations means fair use, fair dealing, and/or
+ any other exception or limitation to Copyright and Similar Rights
+ that applies to Your use of the Licensed Material.
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
+ f. Licensed Material means the artistic or literary work, database,
+ or other material to which the Licensor applied this Public
+ License.
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
+ g. Licensed Rights means the rights granted to You subject to the
+ terms and conditions of this Public License, which are limited to
+ all Copyright and Similar Rights that apply to Your use of the
+ Licensed Material and that the Licensor has authority to license.
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
+ h. Licensor means the individual(s) or entity(ies) granting rights
+ under this Public License.
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
+ i. Share means to provide material to the public by any means or
+ process that requires permission under the Licensed Rights, such
+ as reproduction, public display, public performance, distribution,
+ dissemination, communication, or importation, and to make material
+ available to the public including in ways that members of the
+ public may access the material from a place and at a time
+ individually chosen by them.
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
+ j. Sui Generis Database Rights means rights other than copyright
+ resulting from Directive 96/9/EC of the European Parliament and of
+ the Council of 11 March 1996 on the legal protection of databases,
+ as amended and/or succeeded, as well as other essentially
+ equivalent rights anywhere in the world.
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
+ k. You means the individual or entity exercising the Licensed Rights
+ under this Public License. Your has a corresponding meaning.
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
+Section 2 -- Scope.
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
+ a. License grant.
- END OF TERMS AND CONDITIONS
+ 1. Subject to the terms and conditions of this Public License,
+ the Licensor hereby grants You a worldwide, royalty-free,
+ non-sublicensable, non-exclusive, irrevocable license to
+ exercise the Licensed Rights in the Licensed Material to:
- APPENDIX: How to apply the Apache License to your work.
+ a. reproduce and Share the Licensed Material, in whole or
+ in part; and
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
+ b. produce, reproduce, and Share Adapted Material.
- Copyright [yyyy] [name of copyright owner]
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
+ Exceptions and Limitations apply to Your use, this Public
+ License does not apply, and You do not need to comply with
+ its terms and conditions.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
+ 3. Term. The term of this Public License is specified in Section
+ 6(a).
- http://www.apache.org/licenses/LICENSE-2.0
+ 4. Media and formats; technical modifications allowed. The
+ Licensor authorizes You to exercise the Licensed Rights in
+ all media and formats whether now known or hereafter created,
+ and to make technical modifications necessary to do so. The
+ Licensor waives and/or agrees not to assert any right or
+ authority to forbid You from making technical modifications
+ necessary to exercise the Licensed Rights, including
+ technical modifications necessary to circumvent Effective
+ Technological Measures. For purposes of this Public License,
+ simply making modifications authorized by this Section 2(a)
+ (4) never produces Adapted Material.
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
\ No newline at end of file
+ 5. Downstream recipients.
+
+ a. Offer from the Licensor -- Licensed Material. Every
+ recipient of the Licensed Material automatically
+ receives an offer from the Licensor to exercise the
+ Licensed Rights under the terms and conditions of this
+ Public License.
+
+ b. No downstream restrictions. You may not offer or impose
+ any additional or different terms or conditions on, or
+ apply any Effective Technological Measures to, the
+ Licensed Material if doing so restricts exercise of the
+ Licensed Rights by any recipient of the Licensed
+ Material.
+
+ 6. No endorsement. Nothing in this Public License constitutes or
+ may be construed as permission to assert or imply that You
+ are, or that Your use of the Licensed Material is, connected
+ with, or sponsored, endorsed, or granted official status by,
+ the Licensor or others designated to receive attribution as
+ provided in Section 3(a)(1)(A)(i).
+
+ b. Other rights.
+
+ 1. Moral rights, such as the right of integrity, are not
+ licensed under this Public License, nor are publicity,
+ privacy, and/or other similar personality rights; however, to
+ the extent possible, the Licensor waives and/or agrees not to
+ assert any such rights held by the Licensor to the limited
+ extent necessary to allow You to exercise the Licensed
+ Rights, but not otherwise.
+
+ 2. Patent and trademark rights are not licensed under this
+ Public License.
+
+ 3. To the extent possible, the Licensor waives any right to
+ collect royalties from You for the exercise of the Licensed
+ Rights, whether directly or through a collecting society
+ under any voluntary or waivable statutory or compulsory
+ licensing scheme. In all other cases the Licensor expressly
+ reserves any right to collect such royalties.
+
+
+Section 3 -- License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the
+following conditions.
+
+ a. Attribution.
+
+ 1. If You Share the Licensed Material (including in modified
+ form), You must:
+
+ a. retain the following if it is supplied by the Licensor
+ with the Licensed Material:
+
+ i. identification of the creator(s) of the Licensed
+ Material and any others designated to receive
+ attribution, in any reasonable manner requested by
+ the Licensor (including by pseudonym if
+ designated);
+
+ ii. a copyright notice;
+
+ iii. a notice that refers to this Public License;
+
+ iv. a notice that refers to the disclaimer of
+ warranties;
+
+ v. a URI or hyperlink to the Licensed Material to the
+ extent reasonably practicable;
+
+ b. indicate if You modified the Licensed Material and
+ retain an indication of any previous modifications; and
+
+ c. indicate the Licensed Material is licensed under this
+ Public License, and include the text of, or the URI or
+ hyperlink to, this Public License.
+
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
+ reasonable manner based on the medium, means, and context in
+ which You Share the Licensed Material. For example, it may be
+ reasonable to satisfy the conditions by providing a URI or
+ hyperlink to a resource that includes the required
+ information.
+
+ 3. If requested by the Licensor, You must remove any of the
+ information required by Section 3(a)(1)(A) to the extent
+ reasonably practicable.
+
+ 4. If You Share Adapted Material You produce, the Adapter's
+ License You apply must not prevent recipients of the Adapted
+ Material from complying with this Public License.
+
+
+Section 4 -- Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that
+apply to Your use of the Licensed Material:
+
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
+ to extract, reuse, reproduce, and Share all or a substantial
+ portion of the contents of the database;
+
+ b. if You include all or a substantial portion of the database
+ contents in a database in which You have Sui Generis Database
+ Rights, then the database in which You have Sui Generis Database
+ Rights (but not its individual contents) is Adapted Material; and
+
+ c. You must comply with the conditions in Section 3(a) if You Share
+ all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not
+replace Your obligations under this Public License where the Licensed
+Rights include other Copyright and Similar Rights.
+
+
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
+
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
+
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
+
+ c. The disclaimer of warranties and limitation of liability provided
+ above shall be interpreted in a manner that, to the extent
+ possible, most closely approximates an absolute disclaimer and
+ waiver of all liability.
+
+
+Section 6 -- Term and Termination.
+
+ a. This Public License applies for the term of the Copyright and
+ Similar Rights licensed here. However, if You fail to comply with
+ this Public License, then Your rights under this Public License
+ terminate automatically.
+
+ b. Where Your right to use the Licensed Material has terminated under
+ Section 6(a), it reinstates:
+
+ 1. automatically as of the date the violation is cured, provided
+ it is cured within 30 days of Your discovery of the
+ violation; or
+
+ 2. upon express reinstatement by the Licensor.
+
+ For the avoidance of doubt, this Section 6(b) does not affect any
+ right the Licensor may have to seek remedies for Your violations
+ of this Public License.
+
+ c. For the avoidance of doubt, the Licensor may also offer the
+ Licensed Material under separate terms or conditions or stop
+ distributing the Licensed Material at any time; however, doing so
+ will not terminate this Public License.
+
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
+ License.
+
+
+Section 7 -- Other Terms and Conditions.
+
+ a. The Licensor shall not be bound by any additional or different
+ terms or conditions communicated by You unless expressly agreed.
+
+ b. Any arrangements, understandings, or agreements regarding the
+ Licensed Material not stated herein are separate from and
+ independent of the terms and conditions of this Public License.
+
+
+Section 8 -- Interpretation.
+
+ a. For the avoidance of doubt, this Public License does not, and
+ shall not be interpreted to, reduce, limit, restrict, or impose
+ conditions on any use of the Licensed Material that could lawfully
+ be made without permission under this Public License.
+
+ b. To the extent possible, if any provision of this Public License is
+ deemed unenforceable, it shall be automatically reformed to the
+ minimum extent necessary to make it enforceable. If the provision
+ cannot be reformed, it shall be severed from this Public License
+ without affecting the enforceability of the remaining terms and
+ conditions.
+
+ c. No term or condition of this Public License will be waived and no
+ failure to comply consented to unless expressly agreed to by the
+ Licensor.
+
+ d. Nothing in this Public License constitutes or may be interpreted
+ as a limitation upon, or waiver of, any privileges and immunities
+ that apply to the Licensor or You, including from the legal
+ processes of any jurisdiction or authority.
+
+
+=======================================================================
+
+Creative Commons is not a party to its public
+licenses. Notwithstanding, Creative Commons may elect to apply one of
+its public licenses to material it publishes and in those instances
+will be considered the "Licensor." The text of the Creative Commons
+public licenses is dedicated to the public domain under the CC0 Public
+Domain Dedication. Except for the limited purpose of indicating that
+material is shared under a Creative Commons public license or as
+otherwise permitted by the Creative Commons policies published at
+creativecommons.org/policies, Creative Commons does not authorize the
+use of the trademark "Creative Commons" or any other trademark or logo
+of Creative Commons without its prior written consent including,
+without limitation, in connection with any unauthorized modifications
+to any of its public licenses or any other arrangements,
+understandings, or agreements concerning use of licensed material. For
+the avoidance of doubt, this paragraph does not form part of the
+public licenses.
+
+Creative Commons may be contacted at creativecommons.org.
diff --git a/Readme.md b/Readme.md
index 2521f21..a284506 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,5 +1,5 @@
-
+
@@ -12,8 +12,9 @@
-[![Stars Count](https://img.shields.io/github/stars/sunface/rust-by-practice?style=flat)](https://github.com/sunface/rust-by-practice/stargazers) [![Forks Count](https://img.shields.io/github/forks/sunface/rust-by-practice.svg?style=flat)](https://github.com/naaive/orange/network/members)
-[![LICENSE](https://img.shields.io/badge/license-mit-green?style=flat)](https://github.com/sunface/rust-by-practice/blob/master/LICENSE)
+[![Stars Count](https://img.shields.io/github/stars/sunface/rust-by-practice?style=flat)](https://github.com/sunface/rust-by-practice/stargazers)
+[![studyrut](https://img.shields.io/badge/RustCn-orange)](https://hirust.cn)
+[![LICENSE](https://img.shields.io/badge/license-CC_BY_4.0-green?style=flat)](https://github.com/sunface/rust-by-practice/blob/master/LICENSE)
This book was designed for easily diving into and get skilled with Rust, and it's very easy to use: All you need to do is to make each exercise compile without ERRORS and Panics !
@@ -23,6 +24,45 @@ This book was designed for easily diving into and get skilled with Rust, and it'
- [https://practice.rs](https://practice.rs)
+## Features
+
+Part of our examples and exercises are borrowed from [Rust By Example](https://github.com/rust-lang/rust-by-example), thanks for your great works!
+
+Although they are so awesome, we have our own secret weapons :)
+
+- There are three parts in each chapter: examples, exercises and practices
+
+- Besides examples, we have `a lot of exercises`, you can Read, Edit and Run them ONLINE
+
+- Covering nearly all aspects of Rust, such as async/await, threads, sync primitives, optimizing, standard libraries, tool chain, data structures and algorithms etc.
+
+- Every exercise has its own solutions
+
+- The overall difficulties are a bit higher and from easy to super hard: easy 🌟 medium 🌟🌟 hard 🌟🌟🌟 super hard 🌟🌟🌟🌟
+
+**What we want to do is fill in the gap between learning and getting started with real projects.**
+
+## 🏅 Contributors
+
+Thanks to all of our [contributors](https://github.com/sunface/rust-by-practice/graphs/contributors)!
+
+
+
+**🏆 Special thanks to our English editor:**
+
+
+
+
## Running locally
We use [mdbook](https://rust-lang.github.io/mdBook/) building our exercises. You can run locally with below steps:
@@ -46,24 +86,6 @@ $ cd rust-by-practice && mdbook serve en/
$ cd rust-by-practice && mdbook serve zh-CN/
```
-## Features
-
-Part of our examples and exercises are borrowed from [Rust By Example](https://github.com/rust-lang/rust-by-example), thanks for your great works!
-
-Although they are so awesome, we have our own secret weapons :)
-
-- There are three parts in each chapter: examples, exercises and practices
-
-- Besides examples, we have `a lot of exercises`, you can Read, Edit and Run them ONLINE
-
-- Covering nearly all aspects of Rust, such as async/await, threads, sync primitives, optimizing, standard libraries, tool chain, data structures and algorithms etc.
-
-- Every exercise has its own solutions
-
-- The overall difficulties are a bit higher and from easy to super hard: easy 🌟 medium 🌟🌟 hard 🌟🌟🌟 super hard 🌟🌟🌟🌟
-
-**What we want to do is fill in the gap between learning and getting started with real projects.**
-
## Some of our exercises
🌟🌟🌟 Tuple struct looks similar to tuples, it has added meaning the struct name provides but has no named fields. It's useful when you want give the whole tuple a name, but don't care the fields's names.
diff --git a/en/assets/header.jpg b/en/assets/header.jpg
new file mode 100644
index 0000000..7a18c7a
Binary files /dev/null and b/en/assets/header.jpg differ
diff --git a/en/assets/header1.png b/en/assets/header1.png
new file mode 100644
index 0000000..259779c
Binary files /dev/null and b/en/assets/header1.png differ
diff --git a/en/src/basic-types/char-bool-unit.md b/en/src/basic-types/char-bool-unit.md
index b66b585..87e0223 100644
--- a/en/src/basic-types/char-bool-unit.md
+++ b/en/src/basic-types/char-bool-unit.md
@@ -4,7 +4,7 @@
1. 🌟
```rust, editable
-// make it work
+// Make it work
use std::mem::size_of_val;
fn main() {
let c1 = 'a';
@@ -13,14 +13,14 @@ fn main() {
let c2 = '中';
assert_eq!(size_of_val(&c2),3);
- println!("Success!")
+ println!("Success!");
}
```
2. 🌟
```rust, editable
-// make it work
+// Make it work
fn main() {
let c1 = "中";
print_char(c1);
@@ -35,13 +35,13 @@ fn print_char(c : char) {
3. 🌟
```rust, editable
-// make println! work
+// Make println! work
fn main() {
let _f: bool = false;
let t = true;
if !t {
- println!("Success!")
+ println!("Success!");
}
}
```
@@ -49,13 +49,13 @@ fn main() {
4. 🌟
```rust, editable
-// make it work
+// Make it work
fn main() {
let f = true;
let t = true && false;
assert_eq!(t, f);
- println!("Success!")
+ println!("Success!");
}
```
@@ -64,36 +64,36 @@ fn main() {
5. 🌟🌟
```rust,editable
-// make it work, don't modify `implicitly_ret_unit` !
+// Make it work, don't modify `implicitly_ret_unit` !
fn main() {
let _v: () = ();
let v = (2, 3);
assert_eq!(v, implicitly_ret_unit());
- println!("Success!")
+ println!("Success!");
}
fn implicitly_ret_unit() {
- println!("I will return a ()")
+ println!("I will return a ()");
}
-// don't use this one
+// Don't use this one
fn explicitly_ret_unit() -> () {
- println!("I will return a ()")
+ println!("I will return a ()");
}
```
-6. 🌟🌟 what's the size of the unit type?
+6. 🌟🌟 What's the size of the unit type?
```rust,editable
-// modify `4` in assert to make it work
+// Modify `4` in assert to make it work
use std::mem::size_of_val;
fn main() {
let unit: () = ();
assert!(size_of_val(&unit) == 4);
- println!("Success!")
+ println!("Success!");
}
```
diff --git a/en/src/basic-types/functions.md b/en/src/basic-types/functions.md
index f6adb06..f4d2762 100644
--- a/en/src/basic-types/functions.md
+++ b/en/src/basic-types/functions.md
@@ -3,13 +3,13 @@
```rust,editable
fn main() {
- // don't modify the following two lines!
+ // Don't modify the following two lines!
let (x, y) = (1, 2);
let s = sum(x, y);
assert_eq!(s, 3);
- println!("Success!")
+ println!("Success!");
}
fn sum(x, y: i32) {
@@ -24,9 +24,9 @@ fn main() {
print();
}
-// replace i32 with another type
+// Replace i32 with another type
fn print() -> i32 {
- println!("Success!")
+ println!("Success!");
}
```
@@ -34,16 +34,16 @@ fn print() -> i32 {
3. 🌟🌟🌟
```rust,editable
-// solve it in two ways
+// Solve it in two ways
// DON'T let `println!` works
fn main() {
never_return();
- println!("Failed!")
+ println!("Failed!");
}
fn never_return() -> ! {
- // implement this function, don't modify the fn signatures
+ // Implement this function, don't modify the fn signatures
}
```
@@ -90,11 +90,11 @@ fn main() {
// Diverging functions can also be used in match expression to replace a value of any value
false => {
println!("Success!");
- panic!("we have no value for `false`, but we can panic")
+ panic!("we have no value for `false`, but we can panic");
}
};
- println!("Excercise Failed if printing out this line!");
+ println!("Exercise Failed if printing out this line!");
}
```
diff --git a/en/src/basic-types/numbers.md b/en/src/basic-types/numbers.md
index d0ccbbb..75332ea 100644
--- a/en/src/basic-types/numbers.md
+++ b/en/src/basic-types/numbers.md
@@ -4,49 +4,49 @@
1. 🌟
-> Tips: If we don't explicitly give one type to a varible, then the compiler will infer one for us
+> Tips: If we don't explicitly assign a type to a variable, then the compiler will infer one for us.
```rust,editable
-// remove something to make it work
+// Remove something to make it work
fn main() {
let x: i32 = 5;
let mut y: u32 = 5;
y = x;
- let z = 10; // type of z ?
+ let z = 10; // Type of z ?
- println!("Success!")
+ println!("Success!");
}
```
2. 🌟
```rust,editable
-// fill the blank
+// Fill the blank
fn main() {
let v: u16 = 38_u8 as __;
- println!("Success!")
+ println!("Success!");
}
```
3. 🌟🌟🌟
-> Tips: If we don't explicitly give one type to a varible, then the compiler will infer one for us
+> Tips: If we don't explicitly assign a type to a variable, then the compiler will infer one for us.
```rust,editable
-// modify `assert_eq!` to make it work
+// Modify `assert_eq!` to make it work
fn main() {
let x = 5;
assert_eq!("u32".to_string(), type_of(&x));
- println!("Success!")
+ println!("Success!");
}
-// get the type of given variable, return a string representation of the type , e.g "i8", "u8", "i32", "u32"
+// Get the type of given variable, return a string representation of the type , e.g "i8", "u8", "i32", "u32"
fn type_of(_: &T) -> String {
format!("{}", std::any::type_name::())
}
@@ -55,19 +55,19 @@ fn type_of(_: &T) -> String {
4. 🌟🌟
```rust,editable
-// fill the blanks to make it work
+// Fill the blanks to make it work
fn main() {
assert_eq!(i8::MAX, __);
assert_eq!(u8::MAX, __);
- println!("Success!")
+ println!("Success!");
}
```
5. 🌟🌟
```rust,editable
-// fix errors and panics to make it work
+// Fix errors and panics to make it work
fn main() {
let v1 = 251_u8 + 8;
let v2 = i8::checked_add(251, 8).unwrap();
@@ -78,12 +78,12 @@ fn main() {
6. 🌟🌟
```rust,editable
-// modify `assert!` to make it work
+// Modify `assert!` to make it work
fn main() {
let v = 1_024 + 0xff + 0o77 + 0b1111_1111;
assert!(v == 1579);
- println!("Success!")
+ println!("Success!");
}
```
@@ -93,29 +93,29 @@ fn main() {
```rust,editable
-// replace ? with your answer
+// Replace ? with your answer
fn main() {
let x = 1_000.000_1; // ?
let y: f32 = 0.12; // f32
let z = 0.01_f64; // f64
- println!("Success!")
+ println!("Success!");
}
```
-1. 🌟🌟 make it work in two distinct ways
+1. 🌟🌟 Make it work in two distinct ways
```rust,editable
fn main() {
assert!(0.1+0.2==0.3);
- println!("Success!")
+ println!("Success!");
}
```
### Range
-9. 🌟🌟 two goals: 1. modify `assert!` to make it work 2. make `println!` output: 97 - 122
+9. 🌟🌟 Two goals: 1. Modify `assert!` to make it work 2. Make `println!` output: 97 - 122
```rust,editable
fn main() {
@@ -135,13 +135,13 @@ fn main() {
10. 🌟🌟
```rust,editable
-// fill the blanks
+// Fill the blanks
use std::ops::{Range, RangeInclusive};
fn main() {
assert_eq!((1..__), Range{ start: 1, end: 5 });
assert_eq!((1..__), RangeInclusive::new(1, 5));
- println!("Success!")
+ println!("Success!");
}
```
@@ -150,7 +150,7 @@ fn main() {
11. 🌟
```rust,editable
-// fill the blanks and fix the errors
+// Fill the blanks and fix the errors
fn main() {
// Integer addition
assert!(1u32 + 2 == __);
diff --git a/en/src/basic-types/statements-expressions.md b/en/src/basic-types/statements-expressions.md
index 0d8f022..ff1f83f 100644
--- a/en/src/basic-types/statements-expressions.md
+++ b/en/src/basic-types/statements-expressions.md
@@ -27,7 +27,7 @@ fn main() {
### Exercises
1. 🌟🌟
```rust,editable
-// make it work with two ways
+// Make it work with two ways
fn main() {
let v = {
let mut x = 1;
@@ -36,7 +36,7 @@ fn main() {
assert_eq!(v, 3);
- println!("Success!")
+ println!("Success!");
}
```
@@ -48,7 +48,7 @@ fn main() {
assert!(v == 3);
- println!("Success!")
+ println!("Success!");
}
```
@@ -59,7 +59,7 @@ fn main() {
let s = sum(1 , 2);
assert_eq!(s, 3);
- println!("Success!")
+ println!("Success!");
}
fn sum(x: i32, y: i32) -> i32 {
diff --git a/en/src/collections/hashmap.md b/en/src/collections/hashmap.md
index b02db08..fc2ff7c 100644
--- a/en/src/collections/hashmap.md
+++ b/en/src/collections/hashmap.md
@@ -9,7 +9,7 @@ The hash table implementation is a Rust port of Google’s [SwissTable](https://
### Basic Operations
1. 🌟🌟
-```rust,editbale
+```rust,editable
// FILL in the blanks and FIX the erros
use std::collections::HashMap;
diff --git a/en/src/compound-types/array.md b/en/src/compound-types/array.md
index 92104e1..d884a3b 100644
--- a/en/src/compound-types/array.md
+++ b/en/src/compound-types/array.md
@@ -1,26 +1,26 @@
# Array
-The type of array is `[T; Lengh]`, as you can see, array's lengh is part of their type signature. So their length must be known at compile time.
+The type of array is `[T; Length]`, as you can see, array's length is part of their type signature. So their length must be known at compile time.
-For example, you cant initialized an array as below:
+For example, you cant initialize an array like below:
```rust
fn init_arr(n: i32) {
let arr = [1; n];
}
```
-This will cause an error, because the compile have no idea of the exact size of the array in compile time.
+This will cause an error, because the compiler has no idea of the exact size of the array at compile time.
1. 🌟
```rust,editable
fn main() {
- // fill the blank with proper array type
+ // Fill the blank with proper array type
let arr: __ = [1, 2, 3, 4, 5];
- // modify below to make it work
+ // Modify the code below to make it work
assert!(arr.len() == 4);
- println!("Success!")
+ println!("Success!");
}
```
@@ -28,16 +28,16 @@ fn main() {
```rust,editable
fn main() {
- // we can ignore parts of the array type or even the whole type, let the compiler infer it for us
+ // We can ignore parts of the array type or even the whole type, let the compiler infer it for us
let arr0 = [1, 2, 3];
let arr: [_; 3] = ['a', 'b', 'c'];
- // fill the blank
- // Arrays are stack allocated, `std::mem::size_of_val` return the bytes which array occupies
- // A char takes 4 byte in Rust: Unicode char
+ // Fill the blank
+ // Arrays are stack allocated, `std::mem::size_of_val` returns the bytes which an array occupies
+ // A char takes 4 bytes in Rust: Unicode char
assert!(std::mem::size_of_val(&arr) == __);
- println!("Success!")
+ println!("Success!");
}
```
@@ -46,13 +46,13 @@ fn main() {
```rust,editable
fn main() {
- // fill the blank
+ // Fill the blank
let list: [i32; 100] = __ ;
assert!(list[0] == 1);
assert!(list.len() == 100);
- println!("Success!")
+ println!("Success!");
}
```
@@ -60,10 +60,10 @@ fn main() {
```rust,editable
fn main() {
- // fix the error
+ // Fix the error
let _arr = [1, 2, '3'];
- println!("Success!")
+ println!("Success!");
}
```
@@ -73,28 +73,28 @@ fn main() {
fn main() {
let arr = ['a', 'b', 'c'];
- let ele = arr[1]; // only modify this line to make the code work!
+ let ele = arr[1]; // Only modify this line to make the code work!
assert!(ele == 'a');
- println!("Success!")
+ println!("Success!");
}
```
6. 🌟 Out of bounds indexing causes `panic`.
```rust,editable
-// fix the error
+// Fix the error
fn main() {
let names = [String::from("Sunfei"), "Sunface".to_string()];
- // `get` returns an Option, it's safe to use
+ // `Get` returns an Option, it's safe to use
let name0 = names.get(0).unwrap();
- // but indexing is not safe
+ // But indexing is not safe
let _name1 = &names[2];
- println!("Success!")
+ println!("Success!");
}
```
diff --git a/en/src/compound-types/enum.md b/en/src/compound-types/enum.md
index 19a61a2..d5d1d81 100644
--- a/en/src/compound-types/enum.md
+++ b/en/src/compound-types/enum.md
@@ -3,7 +3,7 @@
```rust,editable
-// fix the errors
+// Fix the errors
enum Number {
Zero,
One,
@@ -25,18 +25,18 @@ enum Number2 {
fn main() {
- // a enum variant can be converted to a integer by `as`
+ // An enum variant can be converted to a integer by `as`
assert_eq!(Number::One, Number1::One);
assert_eq!(Number1::One, Number2::One);
- println!("Success!")
+ println!("Success!");
}
```
-2. 🌟 each enum variant can hold its own data.
+2. 🌟 Each enum variant can hold its own data.
```rust,editable
-// fill in the blank
+// Fill in the blank
enum Message {
Quit,
Move { x: i32, y: i32 },
@@ -45,17 +45,17 @@ enum Message {
}
fn main() {
- let msg1 = Message::Move{__}; // instantiating with x = 1, y = 2
- let msg2 = Message::Write(__); // instantiating with "hello, world!"
+ let msg1 = Message::Move{__}; // Instantiating with x = 1, y = 2
+ let msg2 = Message::Write(__); // Instantiating with "hello, world!"
- println!("Success!")
+ println!("Success!");
}
```
-3. 🌟🌟 we can get the data which a enum variant is holding by pattern match
+3. 🌟🌟 We can get the data which an enum variant is holding by pattern match.
```rust,editable
-// fill in the blank and fix the error
+// Fill in the blank and fix the error
enum Message {
Quit,
Move { x: i32, y: i32 },
@@ -72,7 +72,7 @@ fn main() {
panic!("NEVER LET THIS RUN!");
}
- println!("Success!")
+ println!("Success!");
}
```
@@ -80,7 +80,7 @@ fn main() {
```rust,editable
-// fill in the blank and fix the errors
+// Fill in the blank and fix the errors
enum Message {
Quit,
Move { x: i32, y: i32 },
@@ -105,11 +105,11 @@ fn show_message(msg: Message) {
}
```
-5. 🌟🌟 As there is no `null` in Rust, we have to use enum `Option` to deal the cases when value is absent.
+5. 🌟🌟 Since there is no `null` in Rust, we have to use enum `Option` to deal with the cases when the value is absent.
```rust,editable
-// fill in the blank to make the `println` work.
-// also add some code to prevent the `panic` from running.
+// Fill in the blank to make the `println` work.
+// Also add some code to prevent the `panic` from running.
fn main() {
let five = Some(5);
let six = plus_one(five);
@@ -118,7 +118,7 @@ fn main() {
if let __ = six {
println!("{}", n);
- println!("Success!")
+ println!("Success!");
}
panic!("NEVER LET THIS RUN!");
@@ -133,7 +133,7 @@ fn plus_one(x: Option) -> Option {
```
-6. 🌟🌟🌟🌟 implement a `linked-list` via enums.
+6. 🌟🌟🌟🌟 Implement a `linked-list` via enums.
```rust,editable
@@ -166,12 +166,12 @@ impl List {
// depends on the variant of `self`
// `self` has type `&List`, and `*self` has type `List`, matching on a
// concrete type `T` is preferred over a match on a reference `&T`
- // after Rust 2018 you can use self here and tail (with no ref) below as well,
+ // After Rust 2018 you can use self here and tail (with no ref) below as well,
// rust will infer &s and ref tail.
// See https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/default-match-bindings.html
match *self {
// Can't take ownership of the tail, because `self` is borrowed;
- // instead take a reference to the tail
+ // Instead take a reference to the tail
Cons(_, ref tail) => 1 + tail.len(),
// Base Case: An empty list has zero length
Nil => 0
diff --git a/en/src/compound-types/slice.md b/en/src/compound-types/slice.md
index f535397..b9d149d 100644
--- a/en/src/compound-types/slice.md
+++ b/en/src/compound-types/slice.md
@@ -4,18 +4,18 @@ Slices are similar to arrays, but their length is not known at compile time, so
1. 🌟🌟 Here, both `[i32]` and `str` are slice types, but directly using it will cause errors. You have to use the reference of the slice instead: `&[i32]`, `&str`.
```rust,editable
-// fix the errors, DON'T add new lines!
+// Fix the errors, DON'T add new lines!
fn main() {
let arr = [1, 2, 3];
let s1: [i32] = arr[0..2];
let s2: str = "hello, world" as str;
- println!("Success!")
+ println!("Success!");
}
```
-A slice reference is a two-word object, for simplicity reasons, from now on we will use slice instead of `slice reference`. The first word is a pointer to the data, and the second word is the length of the slice. The word size is the same as usize, determined by the processor architecture eg 64 bits on an x86-64. Slices can be used to borrow a section of an array, and have the type signature `&[T]`.
+A slice reference is a two-word object, for simplicity reasons, from now on we will use slice instead of `slice reference`. The first word is a pointer to the data, and the second word is the length of the slice. The word size is the same as usize, determined by the processor architecture, eg 64 bits on an x86-64. Slices can be used to borrow a section of an array, and have the type signature `&[T]`.
2. 🌟🌟🌟
```rust,editable
@@ -25,11 +25,11 @@ fn main() {
let slice = &arr[..2];
- // modify '6' to make it work
- // TIPS: slice( reference ) IS NOT an array, if it is an array, then `assert!` will passed: each of the two UTF-8 chars '中' and '国' occupies 3 bytes, 2 * 3 = 6
+ // Modify '6' to make it work
+ // TIPS: slice( reference ) IS NOT an array, if it is an array, then `assert!` will passed: Each of the two UTF-8 chars '中' and '国' occupies 3 bytes, 2 * 3 = 6
assert!(std::mem::size_of_val(&slice) == 6);
- println!("Success!")
+ println!("Success!");
}
```
@@ -38,15 +38,15 @@ fn main() {
fn main() {
let arr: [i32; 5] = [1, 2, 3, 4, 5];
- // fill the blanks to make the code work
+ // Fill the blanks to make the code work
let slice: __ = __;
assert_eq!(slice, &[2, 3, 4]);
- println!("Success!")
+ println!("Success!");
}
```
-### string slices
+### String slices
4. 🌟
```rust,editable
@@ -54,12 +54,12 @@ fn main() {
let s = String::from("hello");
let slice1 = &s[0..2];
- // fill the blank to make the code work, DON'T USE 0..2 again
+ // Fill the blank to make the code work, DON'T USE 0..2 again
let slice2 = &s[__];
assert_eq!(slice1, slice2);
- println!("Success!")
+ println!("Success!");
}
```
@@ -68,24 +68,24 @@ fn main() {
fn main() {
let s = "你好,世界";
- // modify this line to make the code work
+ // Modify this line to make the code work
let slice = &s[0..2];
assert!(slice == "你");
- println!("Success!")
+ println!("Success!");
}
```
6. 🌟🌟 `&String` can be implicitly converted into `&str`.
```rust,editable
-// fix errors
+// Fix errors
fn main() {
let mut s = String::from("hello world");
- // here, &s is `&String` type, but `first_word` need a `&str` type.
- // it works because `&String` can be implicitly converted to `&str, If you want know more ,this is called `Deref`
+ // Here, &s is `&String` type, but `first_word` need a `&str` type.
+ // It works because `&String` can be implicitly converted to `&str, If you want know more ,this is called `Deref`
let word = first_word(&s);
s.clear(); // error!
diff --git a/en/src/compound-types/string.md b/en/src/compound-types/string.md
index 57b2d32..627ce5e 100644
--- a/en/src/compound-types/string.md
+++ b/en/src/compound-types/string.md
@@ -1,17 +1,17 @@
-# string
+# String
The type of string literal `"hello, world"` is `&str`, e.g `let s: &str = "hello, world"`.
-### str and &str
-1. 🌟 We can't use `str` type in normal ways, but we can use `&str`
+### Str and &str
+1. 🌟 We can't use `str` type in normal ways, but we can use `&str`.
```rust,editable
-// fix error without adding new line
+// Fix error without adding new line
fn main() {
let s: str = "hello, world";
- println!("Success!")
+ println!("Success!");
}
```
@@ -20,9 +20,9 @@ fn main() {
```rust,editable
-// fix the error with at least two solutions
+// Fix the error with at least two solutions
fn main() {
- let s: Box = "hello, world".into();
+ let s: Box = "hello, world".into();
greetings(s)
}
@@ -37,7 +37,7 @@ fn greetings(s: &str) {
3. 🌟
```rust,editable
-// fill the blank
+// Fill the blank
fn main() {
let mut s = __;
s.push_str("hello, world");
@@ -45,28 +45,28 @@ fn main() {
assert_eq!(s, "hello, world!");
- println!("Success!")
+ println!("Success!");
}
```
4. 🌟🌟🌟
```rust,editable
-// fix all errors without adding newline
+// Fix all errors without adding newline
fn main() {
- let s = String::from("hello");
+ let s = String::from("hello");
s.push(',');
s.push(" world");
s += "!".to_string();
- println!("{}", s)
+ println!("{}", s);
}
```
5. 🌟🌟 `replace` can be used to replace substring
```rust,editable
-// fill the blank
+// Fill the blank
fn main() {
let s = String::from("I like dogs");
// Allocate new memory and store the modified string there
@@ -74,17 +74,17 @@ fn main() {
assert_eq!(s1, "I like cats");
- println!("Success!")
+ println!("Success!");
}
```
More `String` methods can be found under [String](https://doc.rust-lang.org/std/string/struct.String.html) module.
-6. 🌟🌟 You can only concat a `String` with `&str`, and `String`'s ownership can be moved to another variable
+6. 🌟🌟 You can only concat a `String` with `&str`, and `String`'s ownership can be moved to another variable.
```rust,editable
-// fix errors without removing any line
+// Fix errors without removing any line
fn main() {
let s1 = String::from("hello,");
let s2 = String::from("world!");
@@ -100,9 +100,9 @@ Opsite to the seldom using of `str`, `&str` and `String` are used everywhere!
7. 🌟🌟 `&str` can be converted to `String` in two ways
```rust,editable
-// fix error with at lest two solutions
+// Fix error with at least two solutions
fn main() {
- let s = "hello, world";
+ let s = "hello, world";
greetings(s)
}
@@ -115,25 +115,25 @@ fn greetings(s: String) {
```rust,editable
-// use two approaches to fix the error and without adding a new line
+// Use two approaches to fix the error and without adding a new line
fn main() {
- let s = "hello, world".to_string();
+ let s = "hello, world".to_string();
let s1: &str = s;
- println!("Success!")
+ println!("Success!");
}
```
-### string escapes
+### String escapes
9. 🌟
```rust,editable
fn main() {
// You can use escapes to write bytes by their hexadecimal values
- // fill the blank below to show "I'm writing Rust"
+ // Fill the blank below to show "I'm writing Rust"
let byte_escape = "I'm writing Ru\x73__!";
println!("What are you doing\x3F (\\x3F means ?) {}", byte_escape);
- // ...or Unicode code points.
+ // ...Or Unicode code points.
let unicode_codepoint = "\u{211D}";
let character_name = "\"DOUBLE-STRUCK CAPITAL R\"";
@@ -152,9 +152,9 @@ fn main() {
```rust,editable
+/* Fill in the blank and fix the errors */
fn main() {
let raw_str = r"Escapes don't work here: \x3F \u{211D}";
- // modify below line to make it work
assert_eq!(raw_str, "Escapes don't work here: ? ℝ");
// If you need quotes in a raw string, add a pair of #s
@@ -166,15 +166,14 @@ fn main() {
let delimiter = r###"A string with "# in it. And even "##!"###;
println!("{}", delimiter);
- // fill the blank
let long_delimiter = __;
assert_eq!(long_delimiter, "Hello, \"##\"");
- println!("Success!")
+ println!("Success!");
}
```
-### byte string
+### Byte string
Want a string that's not UTF-8? (Remember, str and String must be valid UTF-8). Or maybe you want an array of bytes that's mostly text? Byte strings to the rescue!
**Example**:
@@ -190,8 +189,8 @@ fn main() {
// Byte strings can have byte escapes...
let escaped = b"\x52\x75\x73\x74 as bytes";
- // ...but no unicode escapes
- // let escaped = b"\u{211D} is not allowed";
+ // ...But no unicode escapes
+ // let escaped = b"\u{211D} Is not allowed";
println!("Some escaped bytes: {:?}", escaped);
@@ -208,7 +207,7 @@ fn main() {
like with normal raw strings"#;
// Byte strings don't have to be UTF-8
- let shift_jis = b"\x82\xe6\x82\xa8\x82\xb1\x82\xbb"; // "ようこそ" in SHIFT-JIS
+ let shift_jis = b"\x82\xe6\x82\xa8\x82\xb1\x82\xbb"; // "ようこそ" In SHIFT-JIS
// But then they can't always be converted to `str`
match str::from_utf8(shift_jis) {
@@ -220,29 +219,29 @@ fn main() {
A more detailed listing of the ways to write string literals and escape characters is given in the ['Tokens' chapter](https://doc.rust-lang.org/reference/tokens.html) of the Rust Reference.
-### string index
+### String index
11. 🌟🌟🌟 You can't use index to access a char in a string, but you can use slice `&s1[start..end]`.
```rust,editable
fn main() {
let s1 = String::from("hi,中国");
- let h = s1[0]; //modify this line to fix the error, tips: `h` only takes 1 byte in UTF8 format
+ let h = s1[0]; // Modify this line to fix the error, tips: `h` only takes 1 byte in UTF8 format
assert_eq!(h, "h");
- let h1 = &s1[3..5];//modify this line to fix the error, tips: `中` takes 3 bytes in UTF8 format
+ let h1 = &s1[3..5]; // Modify this line to fix the error, tips: `中` takes 3 bytes in UTF8 format
assert_eq!(h1, "中");
- println!("Success!")
+ println!("Success!");
}
```
-### operate on UTF8 string
+### Operate on UTF8 string
12. 🌟
```rust,editable
fn main() {
- // fill the blank to print each char in "你好,世界"
+ // Fill the blank to print each char in "你好,世界"
for c in "你好,世界".__ {
println!("{}", c)
}
diff --git a/en/src/compound-types/struct.md b/en/src/compound-types/struct.md
index 00dece8..4e6f2fd 100644
--- a/en/src/compound-types/struct.md
+++ b/en/src/compound-types/struct.md
@@ -1,10 +1,10 @@
# Struct
-### There types of structs
+### The types of structs
1. 🌟 We must specify concrete values for each of the fields in struct.
```rust,editable
-// fix the error
+// Fix the error
struct Person {
name: String,
age: u8,
@@ -17,7 +17,7 @@ fn main() {
age,
};
- println!("Success!")
+ println!("Success!");
}
```
@@ -27,35 +27,35 @@ fn main() {
struct Unit;
trait SomeTrait {
- // ...Some behavours defines here
+ // ...Some behaviors defined here.
}
-// We don't care the the fields are in Unit, but we care its behaviors.
+// We don't care about what fields are in the Unit, but we care about its behaviors.
// So we use a struct with no fields and implement some behaviors for it
impl SomeTrait for Unit { }
fn main() {
let u = Unit;
do_something_with_unit(u);
- println!("Success!")
+ println!("Success!");
}
-// fill the blank to make the code work
+// Fill the blank to make the code work
fn do_something_with_unit(u: __) { }
```
-3. 🌟🌟🌟 Tuple struct looks similar to tuples, it has added meaning the struct name provides but has no named fields. It's useful when you want give the whole tuple a name, but don't care the fields's names.
+3. 🌟🌟🌟 Tuple struct looks similar to tuples, it has added meaning the struct name provides but has no named fields. It's useful when you want to give the whole tuple a name, but don't care about the fields's names.
```rust,editable
-// fix the error and fill the blanks
+// Fix the error and fill the blanks
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
fn main() {
let v = Point(__, __, __);
check_color(v);
- println!("Success!")
+ println!("Success!");
}
fn check_color(p: Color) {
@@ -66,13 +66,13 @@ fn check_color(p: Color) {
}
```
-### Operate on structs
+### Operating on structs
-4. 🌟 You can make a whole struct mutable when instantiate it, but Rust doesn't allow us to mark only certain fields as mutable.
+4. 🌟 You can make a whole struct mutable when instantiating it, but Rust doesn't allow us to mark only certain fields as mutable.
```rust,editable
-// fill the blank and fix the error without adding/removing new line
+// Fill the blank and fix the error without adding/removing new line
struct Person {
name: String,
age: u8,
@@ -84,26 +84,26 @@ fn main() {
age,
};
- // how can you believe sunface is only 18?
+ // How can you believe sunface is only 18?
p.age = 30;
- // fill the lank
+ // Fill the blank
__ = String::from("sunfei");
- println!("Success!")
+ println!("Success!");
}
```
-5. 🌟 Using *field init shorthand syntax* to reduct repetitions.
+5. 🌟 Using *field init shorthand syntax* to reduce repetitions.
```rust,editable
-// fill the blank
+// Fill the blank
struct Person {
name: String,
age: u8,
}
fn main() {
- println!("Success!")
+ println!("Success!");
}
fn build_person(name: String, age: u8) -> Person {
@@ -117,7 +117,7 @@ fn build_person(name: String, age: u8) -> Person {
6. 🌟 You can create instance from other instance with *struct update syntax*
```rust,editable
-// fill the blank to make the code work
+// Fill the blank to make the code work
struct User {
active: bool,
username: String,
@@ -134,7 +134,7 @@ fn main() {
let u2 = set_email(u1);
- println!("Success!")
+ println!("Success!");
}
fn set_email(u: User) -> User {
@@ -146,11 +146,11 @@ fn set_email(u: User) -> User {
```
### Print the structs
-7. 🌟🌟 We can use `#[derive(Debug)]` to [make a struct prinable](https://doc.rust-lang.org/book/ch05-02-example-structs.html?highlight=%23%5Bderive(Debug)%5D#adding-useful-functionality-with-derived-traits).
+7. 🌟🌟 We can use `#[derive(Debug)]` to [make a struct printable](https://doc.rust-lang.org/book/ch05-02-example-structs.html?highlight=%23%5Bderive(Debug)%5D#adding-useful-functionality-with-derived-traits).
```rust,editable
-// fill the blanks to make the code work
+// Fill the blanks to make the code work
#[__]
struct Rectangle {
width: u32,
@@ -160,13 +160,13 @@ struct Rectangle {
fn main() {
let scale = 2;
let rect1 = Rectangle {
- width: dbg!(30 * scale), // print debug info to stderr and assign the value of `30 * scale` to `width`
+ width: dbg!(30 * scale), // Print debug info to stderr and assign the value of `30 * scale` to `width`
height: 50,
};
- dbg!(&rect1); // print debug info to stderr
+ dbg!(&rect1); // Print debug info to stderr
- println!(__, rect1); // print debug info to stdout
+ println!(__, rect1); // Print debug info to stdout
}
```
@@ -209,7 +209,7 @@ fn main() {
8. 🌟🌟
```rust,editable
-// fix errors to make it work
+// Fix errors to make it work
#[derive(Debug)]
struct File {
name: String,
diff --git a/en/src/compound-types/tuple.md b/en/src/compound-types/tuple.md
index da45ccc..b882cd6 100644
--- a/en/src/compound-types/tuple.md
+++ b/en/src/compound-types/tuple.md
@@ -6,29 +6,29 @@ fn main() {
let _t0: (u8,i16) = (0, -1);
// Tuples can be tuple's members
let _t1: (u8, (i16, u32)) = (0, (-1, 1));
- // fill the blanks to make the code work
+ // Fill the blanks to make the code work
let t: (u8, __, i64, __, __) = (1u8, 2u16, 3i64, "hello", String::from(", world"));
- println!("Success!")
+ println!("Success!");
}
```
2. 🌟 Members can be extracted from the tuple using indexing.
```rust,editable
-// make it works
+// Make it work
fn main() {
let t = ("i", "am", "sunface");
assert_eq!(t.1, "sunface");
- println!("Success!")
+ println!("Success!");
}
```
3. 🌟 Long tuples cannot be printed
```rust,editable
-// fix the error
+// Fix the error
fn main() {
let too_long_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
println!("too long tuple: {:?}", too_long_tuple);
@@ -41,14 +41,14 @@ fn main() {
fn main() {
let tup = (1, 6.4, "hello");
- // fill the blank to make the code work
+ // Fill the blank to make the code work
let __ = tup;
assert_eq!(x, 1);
assert_eq!(y, "hello");
assert_eq!(z, 6.4);
- println!("Success!")
+ println!("Success!");
}
```
@@ -57,14 +57,14 @@ fn main() {
fn main() {
let (x, y, z);
- // fill the blank
+ // Fill the blank
__ = (1, 2, 3);
assert_eq!(x, 3);
assert_eq!(y, 1);
assert_eq!(z, 2);
- println!("Success!")
+ println!("Success!");
}
```
@@ -72,13 +72,13 @@ fn main() {
```rust,editable
fn main() {
- // fill the blank, need a few computations here.
+ // Fill the blank, need a few computations here.
let (x, y) = sum_multiply(__);
assert_eq!(x, 5);
assert_eq!(y, 6);
- println!("Success!")
+ println!("Success!");
}
fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {
diff --git a/en/src/elegant-code-base.md b/en/src/elegant-code-base.md
index f349b72..8a6876c 100644
--- a/en/src/elegant-code-base.md
+++ b/en/src/elegant-code-base.md
@@ -30,10 +30,15 @@ Tutorial [`https://www.philippflenker.com/hecto/`](https://www.philippflenker.co
[This blog series](https://os.phil-opp.com) creates a small operating system in the Rust programming language. Each post is a small tutorial and includes all needed code, so you can follow along if you like. The source code is also available in the corresponding [Github repository](https://github.com/phil-opp/blog_os).
+
### 7. CodeCrafters.io: Build your own Git, Docker, SQLite, or Redis
On [CodeCrafters](https://codecrafters.io/for/rust), you can recreate your favorite developer tools from scratch. It's a hands-on, minimally-guided approach to master Rust, while appreciating the internals and documentation of popular technology that we use every day.
+### 8. mini-redis
+[mini-redis](https://github.com/tokio-rs/mini-redis) is an incomplete Redis client and server implementation using tokio, it has decent code base and detail explanations, very suitable for learning Rust and asynchronous programming.
+
+
---
diff --git a/en/src/flow-control.md b/en/src/flow-control.md
index ac19d87..0443c8a 100644
--- a/en/src/flow-control.md
+++ b/en/src/flow-control.md
@@ -1,10 +1,10 @@
# Flow control
-### if/else
+### If/else
1. 🌟
```rust,editable
-// fill in the blanks
+// Fill in the blanks
fn main() {
let n = 5;
@@ -18,10 +18,10 @@ fn main() {
}
```
-2. 🌟🌟 `if/else` expression can be used in assignments.
+2. 🌟🌟 `If/else` expression can be used in assignments.
```rust,editable
-// fix the errors
+// Fix the errors
fn main() {
let n = 5;
@@ -40,7 +40,7 @@ fn main() {
}
```
-### for
+### For
3. 🌟 The `for in` construct can be used to iterate through an Iterator, e.g a range `a..b`.
```rust,editable
@@ -52,7 +52,7 @@ fn main() {
}
}
- println!("Success!")
+ println!("Success!");
}
```
@@ -60,19 +60,19 @@ fn main() {
4. 🌟🌟
```rust,editable
-// fix the errors without adding or removing lines
+// Fix the errors without adding or removing lines
fn main() {
let names = [String::from("liming"),String::from("hanmeimei")];
for name in names {
- // do something with name...
+ // Do something with name...
}
println!("{:?}", names);
let numbers = [1, 2, 3];
- // the elements in numbers are Copy,so there is no move here
+ // The elements in numbers are Copy,so there is no move here
for n in numbers {
- // do something with name...
+ // Do something with name...
}
println!("{:?}", numbers);
@@ -84,19 +84,19 @@ fn main() {
fn main() {
let a = [4, 3, 2, 1];
- // iterate the indexing and value in 'a'
+ // Iterate the indexing and value in 'a'
for (i,v) in a.__ {
println!("The {}th element is {}",i+1,v);
}
}
```
-### while
+### While
6. 🌟🌟 The `while` keyword can be used to run a loop when a condition is true.
```rust,editable
-// fill in the blanks to make the last println! work !
+// Fill in the blanks to make the last println! work !
fn main() {
// A counter variable
let mut n = 1;
@@ -117,15 +117,15 @@ fn main() {
__;
}
- println!("n reached {}, soloop is over",n);
+ println!("n reached {}, so loop is over",n);
}
```
-### continue and break
-7. 🌟 use `break` to break the loop.
+### Continue and break
+7. 🌟 Use `break` to break the loop.
```rust,editable
-// fill in the blank
+// Fill in the blank
fn main() {
let mut n = 0;
for i in 0..=100 {
@@ -137,14 +137,14 @@ fn main() {
assert_eq!(n, 66);
- println!("Success!")
+ println!("Success!");
}
```
8. 🌟🌟 `continue` will skip over the remaining code in current iteration and go to the next iteration.
```rust,editable
-// fill in the blanks
+// Fill in the blanks
fn main() {
let mut n = 0;
for i in 0..=100 {
@@ -158,17 +158,17 @@ fn main() {
assert_eq!(n, 66);
- println!("Success!")
+ println!("Success!");
}
```
-### loop
+### Loop
-9. 🌟🌟 loop is usually used together with `break` or `continue`.
+9. 🌟🌟 Loop is usually used together with `break` or `continue`.
```rust,editable
-// fill in the blanks
+// Fill in the blanks
fn main() {
let mut count = 0u32;
@@ -196,14 +196,14 @@ fn main() {
assert_eq!(count, 5);
- println!("Success!")
+ println!("Success!");
}
```
-10. 🌟🌟 loop is an expression, so we can use it with `break` to return a value
+10. 🌟🌟 Loop is an expression, so we can use it with `break` to return a value
```rust,editable
-// fill in the blank
+// Fill in the blank
fn main() {
let mut counter = 0;
@@ -217,7 +217,7 @@ fn main() {
assert_eq!(result, 20);
- println!("Success!")
+ println!("Success!");
}
```
@@ -225,14 +225,14 @@ fn main() {
```rust,editable
-// fill in the blank
+// Fill in the blank
fn main() {
let mut count = 0;
'outer: loop {
'inner1: loop {
if count >= 20 {
// This would break only the inner1 loop
- break 'inner1; // `break` is also ok
+ break 'inner1; // `break` is also works.
}
count += 2;
}
@@ -252,7 +252,7 @@ fn main() {
assert!(count == __);
- println!("Success!")
+ println!("Success!");
}
```
diff --git a/en/src/functional-programing/cloure.md b/en/src/functional-programing/cloure.md
index 7546057..25b77ac 100644
--- a/en/src/functional-programing/cloure.md
+++ b/en/src/functional-programing/cloure.md
@@ -173,7 +173,7 @@ fn main() {
fn main() {
let mut s = String::new();
- let update_string = |str| s.push_str(str);
+ let update_string = |str| s.push_str(str);
exec(update_string);
@@ -260,7 +260,7 @@ move closures may still implement `Fn` or `FnMut`, even though they capture vari
fn main() {
let s = String::new();
- let update_string = move || println!("{}",s);
+ let update_string = move || println!("{}",s);
exec(update_string);
}
@@ -275,7 +275,7 @@ The following code also has no error:
fn main() {
let s = String::new();
- let update_string = move || println!("{}",s);
+ let update_string = move || println!("{}",s);
exec(update_string);
}
diff --git a/en/src/generics-traits/advanced-traits.md b/en/src/generics-traits/advanced-traits.md
index c761aba..7355dea 100644
--- a/en/src/generics-traits/advanced-traits.md
+++ b/en/src/generics-traits/advanced-traits.md
@@ -9,7 +9,7 @@ pub trait CacheableItem: Clone + Default + fmt::Debug + Decodable + Encodable {
}
```
-Using of `Address` is much more clearable and convenient than `AsRef<[u8]> + Clone + fmt::Debug + Eq + Hash`.
+Using of `Address` is much more clearer and convenient than `AsRef<[u8]> + Clone + fmt::Debug + Eq + Hash`.
1. 🌟🌟🌟
```rust,editable
@@ -89,7 +89,7 @@ fn main() {
assert_eq!(Point { x: 2, y: 3 } - Point { x: 1, y: 0 },
Point { x: 1, y: 3 });
- println!("Success!")
+ println!("Success!");
}
```
@@ -110,7 +110,7 @@ trait AgeWidget {
fn get(&self) -> u8;
}
-// A form with both a UsernameWidget and an AgeWidget
+// A form with both a UsernameWidget and an AgeWidget.
struct Form {
username: String,
age: u8,
@@ -141,10 +141,10 @@ fn main() {
let username = UsernameWidget::get(&form);
assert_eq!("rustacean".to_owned(), username);
- let age = AgeWidget::get(&form); // you can also use `