├── .gitattributes ├── .github └── workflows │ ├── lint.yml │ └── sync.yml ├── .gitignore ├── .vscode └── settings.json ├── LICENSE-Apache-2.0 ├── LICENSE-MIT ├── README.md ├── bin ├── install.ps1 └── install.sh ├── dist ├── v1.71.0.zip └── v1.71.0_contrast.zip └── docs ├── BuildHtml.md ├── Install.md └── assets ├── 2021-12-17_19.31.02.png ├── 2021-12-17_20.10.20.png └── 2021-12-17_20.19.25.png /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-language=Rust 2 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | # on: [ push, pull_request ] 4 | 5 | jobs: 6 | lint: 7 | name: AutoCorrect 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Check source code 11 | uses: actions/checkout@main 12 | 13 | - name: AutoCorrect 14 | uses: huacnlee/autocorrect-action@main 15 | -------------------------------------------------------------------------------- /.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: Sync Mirror 2 | 3 | on: [ push, pull_request ] 4 | 5 | # 确保一次只运行一个镜像任务 6 | concurrency: 7 | group: git-mirror 8 | 9 | jobs: 10 | # 自动同步镜像 11 | git-mirror: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: wearerequired/git-mirror-action@v1 15 | env: 16 | SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} 17 | with: 18 | source-repo: 'git@github.com:wtklbm/rust-library-i18n.git' 19 | destination-repo: 'git@gitee.com:wtklbm/rust-library-chinese.git' 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Rust ### 2 | /target/ 3 | Cargo.lock 4 | 5 | /cargo-timing.html 6 | /cargo-timing-*.html 7 | 8 | ### VisualStudioCode ### 9 | .vscode/* 10 | !.vscode/settings.json 11 | !.vscode/tasks.json 12 | !.vscode/launch.json 13 | !.vscode/extensions.json 14 | *.code-workspace 15 | .VSCodeCounter/ 16 | 17 | # Ignore all local history of files 18 | .history 19 | .ionide 20 | 21 | # intellij 22 | .idea/ 23 | .idea_modules/ 24 | 25 | ### Windows ### 26 | # Windows thumbnail cache files 27 | Thumbs.db 28 | Thumbs.db:encryptable 29 | ehthumbs.db 30 | ehthumbs_vista.db 31 | 32 | # Dump file 33 | *.stackdump 34 | 35 | # Folder config file 36 | [Dd]esktop.ini 37 | 38 | # Recycle Bin used on file shares 39 | $RECYCLE.BIN/ 40 | 41 | # Windows Installer files 42 | *.cab 43 | *.msi 44 | *.msix 45 | *.msm 46 | *.msp 47 | 48 | # Windows shortcuts 49 | *.lnk 50 | 51 | ### macOS ### 52 | # General 53 | .DS_Store 54 | .AppleDouble 55 | .LSOverride 56 | 57 | # Icon must end with two \r 58 | Icon 59 | 60 | # Thumbnails 61 | ._* 62 | 63 | # Files that might appear in the root of a volume 64 | .DocumentRevisions-V100 65 | .fseventsd 66 | .Spotlight-V100 67 | .TemporaryItems 68 | .Trashes 69 | .VolumeIcon.icns 70 | .com.apple.timemachine.donotpresent 71 | 72 | # Directories potentially created on remote AFP share 73 | .AppleDB 74 | .AppleDesktop 75 | Network Trash Folder 76 | Temporary Items 77 | .apdisk 78 | 79 | ### Linux ### 80 | *~ 81 | 82 | # temporary files which can be created if a process still has a handle open of a deleted file 83 | .fuse_hidden* 84 | 85 | # KDE directory preferences 86 | .directory 87 | 88 | # Linux trash folder which might appear on any partition or disk 89 | .Trash-* 90 | 91 | # .nfs files are created when an open file is removed but is still being accessed 92 | .nfs* 93 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "Gitee", 4 | "rustlib", 5 | "toolchains" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE-Apache-2.0: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 wtklbm 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 wtklbm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > 2023 年 7 月 28 日更新:我已经对该项目维护两年多了,可我想暂停对该仓库的更新了。一方面是我认为文档还可以做的更好,有很多我想实现的点,可我没有时间去做;另一方面,我是做前端的,没有 Rust 工作,如果哪天有人招我做 Rust 了,有 Rust 工作了,可以考虑重新维护。 2 | 3 | #### 在 IDE 中使用中文文档 4 | 5 | 请查看:[使用 Rust 中文文档](./docs/Install.md) 6 | 7 | #### 离线 HTML 中文 API 文档 8 | 9 | 请查看:[构建离线 HTML 文档](./docs/BuildHtml.md) 10 | 11 | #### Gitee 国内镜像 12 | 13 | 为方便国内同学的下载和访问,[rust-library-i18n](https://github.com/wtklbm/rust-library-i18n) 仓库已同步到了 [rust-library-chinese](https://gitee.com/wtklbm/rust-library-chinese)。 14 | 15 | #### 使用前的注意事项 16 | 17 | - **该翻译是机器翻译自动生成的,没有任何形式的保证,使用该仓库提供的内容,则表示您同意且愿意自行承担使用该翻译所带来的所有风险。** 18 | - **网上充斥着大量低版本的文档,里面有很多问题,非常不建议使用,如果有能力,推荐自行构建最新的 HTML 文档。不要看老版本的!不要看老版本的!不要看老版本的!** 19 | 20 | 感谢所有为项目 [作出贡献的同学](https://github.com/wtklbm/rust-library-i18n/graphs/contributors),和所有提供宝贵意见的同学。 21 | 22 | #### Others 23 | 24 | ##### `crm` 25 | 26 | [crm](https://github.com/wtklbm/crm) 是一个镜像源管理工具,内置了 5 种 Rust 国内镜像源,并提供了测速功能,更换镜像源特别方便。 27 | 28 | #### License 29 | 30 | 该翻译的相关源代码来自于 。 31 | 32 | MIT OR Apache-2.0 33 | -------------------------------------------------------------------------------- /bin/install.ps1: -------------------------------------------------------------------------------- 1 | # 感谢 [tch1121](https://github.com/tch1121) 2 | 3 | function PrintError { 4 | Write-Host " [ERROR] " -NoNewline -ForegroundColor Red 5 | Write-Host @args -ForegroundColor White 6 | } 7 | 8 | function PrintInfo { 9 | Write-Host " [INFO] " -NoNewline -ForegroundColor Green 10 | Write-Host @args -ForegroundColor White 11 | } 12 | 13 | function PrintWarn { 14 | Write-Host " [WARN] " -NoNewline -ForegroundColor Yellow 15 | Write-Host @args -ForegroundColor White 16 | } 17 | 18 | function ReadHost { 19 | Write-Host " [WARN] " -NoNewline -ForegroundColor Yellow 20 | return $(Read-Host @args).ToLower() 21 | } 22 | 23 | function IsDir { 24 | param($path) 25 | 26 | return $path -and (Test-Path $path -PathType Container) 27 | } 28 | 29 | function IsFile { 30 | param($path) 31 | 32 | return $path -and (Test-Path $path -PathType Leaf) 33 | } 34 | 35 | function RemoveItem() { 36 | param($path) 37 | 38 | if ($(IsFile $path) -or $(IsDir $path)) { 39 | Remove-Item $path -Recurse -Force 40 | } 41 | } 42 | 43 | function GetRustVersion { 44 | $curr_version = ((rustc --version) -split " ")[1] 45 | 46 | if ($curr_version) { 47 | return $curr_version 48 | } 49 | 50 | PrintError '获取 Rust 版本失败' 51 | } 52 | 53 | function GetLibraryPath { 54 | [System.IO.Path]::GetFullPath( 55 | "$(rustup show home)\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust" 56 | ) 57 | } 58 | 59 | function ExistsCommand { 60 | param($command) 61 | 62 | !($null -eq (Get-Command -Name $command -ErrorAction Ignore)) 63 | } 64 | 65 | function ExtractZipFrom7z { 66 | param($filename, $dirname) 67 | 68 | $filename = $("" + $filename).TrimEnd("\") 69 | & 7z.exe x $filename -aoa $("-o" + $dirname) | Out-Null 70 | } 71 | 72 | function ExtractZip { 73 | param($filename, $dirname, $remove) 74 | 75 | $filename = $("" + $filename).TrimEnd("\") 76 | 77 | if (!$(ExistsCommand Expand-Archive)) { 78 | if (!$(ExistsCommand 7z)) { 79 | PrintError "请先安装 7z,然后重新执行安装" 80 | exit 81 | } 82 | 83 | ExtractZipFrom7z $filename $dirname 84 | exit 85 | } 86 | 87 | try { 88 | Expand-Archive -Path "$filename" -DestinationPath "$dirname" -Force 89 | } 90 | catch { 91 | PrintWarn "解压失败,请重新尝试安装" 92 | exit 93 | } 94 | 95 | if ($remove) { 96 | RemoveItem $filename 97 | } 98 | } 99 | 100 | function RequestDoc { 101 | param ($filename) 102 | 103 | $cfilename = $filename 104 | $tempdir = Join-Path $env:TEMP "rust-library-chinese" 105 | 106 | RemoveItem $tempdir 107 | 108 | $RepositoriesList = @{ 109 | 'github' = 'https://github.com/wtklbm/rust-library-i18n.git' 110 | 'gitee' = 'https://gitee.com/wtklbm/rust-library-chinese.git' 111 | } 112 | 113 | $Repositories = ReadHost "请选择仓库源 (输入数字。默认: 1)`n [0]: github`n [1]: gitee" 114 | $Repositories -match '^\[?(?[0-1])\]?$' | Out-Null 115 | $Repositories = if ($Matches.target -eq 0) { $RepositoriesList.github } else { $RepositoriesList.gitee } 116 | 117 | PrintInfo "正在从远程下载中文文档... (可能会很长时间,请耐心等待)" 118 | 119 | git clone --depth 1 -q $Repositories $tempdir 120 | 121 | $distPath = $(Join-Path $tempdir "dist") 122 | 123 | if (!$(IsDir $distPath)) { 124 | PrintError "克隆仓库失败,请尝试重新安装" 125 | exit 126 | } 127 | 128 | $style = ReadHost "请选择文档样式 (输入数字。默认: 0)`n [0]: 纯中文文档。阅读方便,有看不懂的地方直接看官网原文和源码`n [1]: 对照文档。阅读起来比较慢,中文翻译只作为参考" 129 | $style -match '^\[?(?[0-1])\]?$' | Out-Null 130 | 131 | $style = if ($Matches.target -eq 1) { 132 | $filename = $filename -replace ".zip", "_contrast.zip" 133 | } 134 | 135 | $filepath = Join-Path $distPath $filename 136 | 137 | if (!$(IsFile $filepath)) { 138 | $basename = $(Get-ChildItem $distPath)[0].BaseName.Substring(1) 139 | PrintError "没有找到当前通道的 Rust 版本所对应的中文文档。找到了 $basename 版本的中文文档。" 140 | exit 141 | } 142 | 143 | Copy-Item $filepath "./$cfilename" 144 | RemoveItem $tempdir 145 | } 146 | 147 | function Install { 148 | PrintInfo "Rust 中文文档安装脚本:`n" 149 | 150 | if (!$(ExistsCommand git)) { 151 | PrintError "请先安装 git,然后重新执行安装" 152 | return 153 | } 154 | 155 | if (!$(ExistsCommand rustup)) { 156 | $url = "https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe" 157 | $exe = "rustup-init.exe" 158 | 159 | # `-UseBasicParsing`: 解决禁用 `IE` 时下载无法解析的问题 160 | Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $exe 161 | 162 | if (!$(IsFile $exe)) { 163 | PrintError "请手动安装 Rust 后重试" 164 | return 165 | } 166 | 167 | PrintError "请先手动执行当前目录下的 $exe 文件来安装 Rust" 168 | return 169 | } 170 | 171 | $is_install = ReadHost "您确定安装 Rust 中文文档吗?安装中文文档时会切换到 stable 通道,并且会安装 rust-src 组件。如果继续请输入 y 或 n (默认: y)" 172 | 173 | if ($is_install -eq 'n') { 174 | return 175 | } 176 | 177 | rustup default stable >$null 2>&1 178 | rustup component add rust-src >$null 2>&1 179 | 180 | $version = "$(GetRustVersion)" 181 | $filename = "v$version.zip" 182 | 183 | PrintInfo "当前 Rust 版本是:$version" 184 | 185 | RequestDoc $filename 186 | 187 | $cwdpath = "$(GetLibraryPath)" 188 | $library = Join-Path $cwdpath 'library' 189 | 190 | if (!$(IsDir $library)) { 191 | PrintError "请检查该目录是否存在:$library" 192 | return 193 | } 194 | 195 | $backup = Join-Path $cwdpath 'library_backup' 196 | $is_install = ReadHost "您需要备份 rust-src 组件中附带的源文件吗?如果继续请输入 y 或 n (默认: n)" 197 | 198 | if ($is_install -eq 'y') { 199 | PrintInfo "源文件已备份到 $backup" 200 | Copy-Item -Recurse -Force "$library" "$backup" 201 | } 202 | 203 | ExtractZip $filename $cwdpath $True 204 | 205 | Write-Output "" 206 | PrintInfo "安装完成!`n" 207 | PrintWarn "请确保在 IDE 中安装了 Rust 相关插件:" 208 | Write-Output " - Visual Studio Code 需要安装 [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer)" 209 | Write-Output " - JetBrains 系列需要安装 [Rust](https://plugins.jetbrains.com/plugin/8182-rust)" 210 | Write-Output '' 211 | PrintInfo "安装好插件后,重新启动你的 IDE 看看吧。祝您编码愉快!" 212 | } 213 | 214 | Install 215 | -------------------------------------------------------------------------------- /bin/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 感谢 [Tarhyru](https://github.com/Tarhyru) 4 | 5 | print_error() { 6 | echo -e "\033[31m [ERROR]\033[0m $*" 7 | } 8 | 9 | print_info() { 10 | echo -e "\033[32m [INFO]\033[0m $*" 11 | } 12 | 13 | print_warn() { 14 | echo -e "\033[33m [WARN]\033[0m $*" 15 | } 16 | 17 | request_doc() { 18 | filename=$1 19 | rust_path=$2 20 | 21 | repositories_list=( 22 | 'https://github.com/wtklbm/rust-library-i18n.git' 23 | 'https://gitee.com/wtklbm/rust-library-chinese.git' 24 | ) 25 | 26 | print_warn "请选择仓库源 (输入数字。默认: 1)" 27 | echo -e " \033[32m[0]\033[0m: github" 28 | echo -e " \033[32m[1]\033[0m: gitee" 29 | 30 | read -r repository 31 | 32 | if [ "$repository" = 0 ]; then 33 | repository=${repositories_list[0]} 34 | else 35 | repository=${repositories_list[1]} 36 | fi 37 | 38 | tmpdir='/tmp/rust-library-chinese' 39 | 40 | rm -rf $tmpdir 41 | mkdir $tmpdir 42 | 43 | print_info "正在从远程下载中文文档... (可能会很长时间,请耐心等待)" 44 | 45 | git clone --depth 1 "$repository" $tmpdir >/dev/null 2>&1 || { 46 | print_error "克隆仓库失败,请重试" 47 | return 0 48 | } 49 | 50 | print_warn "请选择文档样式 (输入数字。默认: 0)" 51 | echo -e " \033[32m[0]\033[0m: 纯中文文档。阅读方便,有看不懂的地方直接看官网原文和源码" 52 | echo -e " \033[32m[1]\033[0m: 对照文档。阅读起来比较慢,中文翻译只作为参考" 53 | 54 | read -r style 55 | 56 | if [ "$style" = 1 ]; then 57 | filename=${filename/".zip"/"_contrast.zip"} 58 | fi 59 | 60 | distpath="$tmpdir/dist" 61 | filepath="$distpath/$filename" 62 | 63 | if [ -f "$filepath" ]; then 64 | cp "$filepath" "$rust_path" 65 | rm -rf $tmpdir 66 | return 1 67 | fi 68 | 69 | basename=$(basename "$(find "$distpath" -path "*/v*")" .zip) 70 | 71 | print_error "没有找到当前通道的 Rust 版本所对应的中文文档。找到了 $basename 版本的中文文档。" 72 | 73 | return 0 74 | } 75 | 76 | install() { 77 | print_info "Rust 中文文档安装脚本:\n" 78 | 79 | if ! (command -v unzip &>/dev/null || command -v 7z &>/dev/null); then 80 | print_error '请先安装 unzip 或 p7zip,然后重新执行安装' 81 | return 82 | fi 83 | 84 | if ! command -v git &>/dev/null; then 85 | print_error '请先安装 git,然后重新执行安装' 86 | return 87 | fi 88 | 89 | if ! command -v rustup &>/dev/null; then 90 | print_info '正在安装 Rust ...' 91 | 92 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh || { 93 | print_error "安装 Rust 失败,请重新尝试" 94 | return 95 | } 96 | 97 | source "$HOME"/.cargo/env 98 | fi 99 | 100 | print_warn "您确定安装 Rust 中文文档吗?安装中文文档时会切换到 stable 通道,并且会安装 rust-src 组件。如果继续请输入 y 或 n (默认: y)" 101 | 102 | read -r is_install 103 | 104 | if [ "$is_install" == "n" ]; then 105 | return 106 | fi 107 | 108 | rustup default stable >/dev/null 2>&1 109 | rustup component add rust-src >/dev/null 2>&1 110 | 111 | version=$(rustc --version | awk '{print $2}') 112 | filename="v$version.zip" 113 | rust_home=$(rustup show home) 114 | 115 | # 路径格式为:`$rust_home/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust` 116 | rust_path=$(find "$rust_home" -path "*stable-*rustlib/src/rust") 117 | 118 | library_path="$rust_path/library" 119 | 120 | print_info "当前 Rust 版本是:$version" 121 | 122 | if [ ! -d "$library_path" ]; then 123 | print_error "没有获取到 library 路径: $library_path" 124 | return 125 | fi 126 | 127 | request_doc "$filename" "$rust_path" 128 | has_doc=$? 129 | 130 | if [ $has_doc == 0 ]; then 131 | return 132 | fi 133 | 134 | print_warn "您需要备份 rust-src 组件中附带的源文件吗?如果继续请输入 y 或 n (默认: n)" 135 | 136 | read -r is_backup 137 | 138 | if [ "$is_backup" = "y" ]; then 139 | backup_dir="$rust_path/library_backup" 140 | cp -rf "$library_path" "$backup_dir" 141 | print_info "源文件已备份到 $backup_dir" 142 | fi 143 | 144 | cd "$rust_path" || { 145 | print_error "请检查目录是否存在:$rust_path" 146 | return 147 | } 148 | 149 | unzip -oq "$filename" &>/dev/null || 7z x -aoa "$filename" &>/dev/null || { 150 | print_error "尝试解压 $filename 失败" 151 | return 152 | } 153 | 154 | rm "$filename" 155 | 156 | print_info "安装完成!\n" 157 | print_warn "请确保在 IDE 中安装了 Rust 相关插件:" 158 | echo -e " - Visual Studio Code 需要安装 [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer)" 159 | echo -e " - JetBrains 系列需要安装 [Rust](https://plugins.jetbrains.com/plugin/8182-rust)" 160 | echo '' 161 | print_info "安装好插件后,重新启动你的 IDE 看看吧。祝您编码愉快!" 162 | } 163 | 164 | install 165 | -------------------------------------------------------------------------------- /dist/v1.71.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtklbm/rust-library-i18n/49f8ccc483bcbc6cf915ad712a25fc9103911043/dist/v1.71.0.zip -------------------------------------------------------------------------------- /dist/v1.71.0_contrast.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtklbm/rust-library-i18n/49f8ccc483bcbc6cf915ad712a25fc9103911043/dist/v1.71.0_contrast.zip -------------------------------------------------------------------------------- /docs/BuildHtml.md: -------------------------------------------------------------------------------- 1 | # 构建离线 HTML 文档 2 | 3 | 您可以构建离线的 HTML 文档供自己阅读。在构建离线 HTML 文档之前,您需要了解一些 Git 操作知识以及 Rust 构建流程。在这里,仅提供 HTML 离线文档的构建命令,有关更多详细信息,请参见 [Rust 官方仓库](https://github.com/rust-lang/rust)。 4 | 5 | 下面所提供的构建 HTML 文档的脚本并不总是有效的。如果您从来没有通过源代码构建过 Rust 文档。那么请避免随意尝试,会出现各种各样的问题。如果您想通过源码构建文档,最快最直接的方式是跳转到 Rust 官方仓库,了解 Rust 构建流程,通过自身的学习,以此探索更好的构建 HTML 文档的操作。 6 | 7 | 之前,[cxping](https://github.com/cxping) 同学构建过一份儿离线中英文对照文档,但长时间无人更新此文档,它显得已经有些老旧,故已将其删除。目前还没有人愿意长期更新本地文档的 HTML 版本,所以即便您构建出 HTML 文档,也请不要向该仓库提交 PR。 8 | 9 | 10 | 11 | 12 | ## 第一步:克隆和替换 13 | 14 | ```bash 15 | # 在终端中执行 16 | 17 | # 克隆 Rust 官方仓库 18 | git clone https://github.com/rust-lang/rust.git rust 19 | 20 | # NOTE: 后续操作将在这个目录下完成 21 | cd rust 22 | 23 | # 切换版本号 24 | # 注意:这里的版本号应该与要构建的中文文档的版本号保持一致 25 | # 特别注意:下面这一行不能直接拷贝,版本号 `1.55.0` 一定要记得改 26 | git checkout 1.55.0 27 | 28 | # 删除 `rust/library` 目录 29 | rm -rf ./library 30 | 31 | # 克隆子仓库 32 | git clone https://github.com/rust-lang/rust-installer.git src/tools/rust-installer 33 | git clone https://github.com/rust-lang/cargo.git src/tools/cargo 34 | git clone https://github.com/rust-lang/rls.git src/tools/rls 35 | git clone https://github.com/rust-lang/miri.git src/tools/miri 36 | git clone https://github.com/rust-lang/stdarch.git library/stdarch 37 | git clone https://github.com/rust-lang/backtrace-rs.git library/backtrace 38 | git clone https://github.com/rust-lang/libbacktrace library/backtrace/crates/backtrace-sys/src/libbacktrace 39 | 40 | # 替换中文文档 41 | # 文档下载地址:https://github.com/wtklbm/rust-library-i18n/tree/main/dist 42 | # 将中文文档复制到 `rust/library` 目录下,已经存在的,直接选择替换 43 | 44 | # 本地提交一次 45 | git add -A 46 | git commit -m none 47 | ``` 48 | 49 | ## 第二步:添加配置 50 | 51 | ```bash 52 | # Linux/macOS Bash 53 | echo -e "changelog-seen = 2\n[llvm]\nninja = false" >> config.toml 54 | 55 | # Windows PowerShell 56 | Write-Output "changelog-seen = 2`n[llvm]`nninja = false" >> config.toml 57 | ``` 58 | 59 | ## 第三步:构建离线文档 60 | 61 | ```bash 62 | # 构建 HTML 离线静态文档 63 | # 关于为什么执行下面的命令能构建文档,请跳转到 Rust 官方仓库 64 | # 有关任何关于该命令的问题,也请到相关仓库进行提问 65 | python x.py doc library/std 66 | 67 | # 构建的结果将自动保存在 `rust/build/x86_64-pc-windows-msvc/doc` 目录下 68 | # 构建完成后,请通过浏览器打开 `rust/build/x86_64-pc-windows-msvc/doc/std/index.html` 文件 69 | ``` 70 | -------------------------------------------------------------------------------- /docs/Install.md: -------------------------------------------------------------------------------- 1 | # 在 IDE 中使用 Rust 标准库中文文档 2 | 3 | 在 `dist` 目录下一共提供了两个文件,它们都是构建好的中文文档。其中一个文件的后缀是带有 `contrast` 字样。这两个文件有一些区别: 4 | 5 | 不带有 `contrast` 字样的文档是纯中文文档,英文内容都被直接替换为中文了。 6 | 7 | ![2021-12-17_20.10.20](./assets/2021-12-17_20.10.20.png) 8 | 9 | 而带有 `contrast` 字样的文档是对照文档,是在英文语句的后面追加了中文翻译语句,实现了中英文并列显示。 10 | 11 | ![2021-12-17_19.31.02](./assets/2021-12-17_19.31.02.png) 12 | 13 | ## 安装中文文档 14 | 15 | ### 通过脚本安装 16 | 17 | #### Windows 18 | 19 | ```powershell 20 | # 在 `Powershell` 中执行 21 | # 该脚本会请求并执行当前项目下的 `bin/install.ps1` 22 | 23 | powershell.exe -encodedCommand ([Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Invoke-WebRequest -Uri "https://gitee.com/wtklbm/rust-library-chinese/raw/main/bin/install.ps1").Content))) 24 | ``` 25 | 26 | #### macOS 或 Linux 27 | 28 | ```bash 29 | # 在终端中执行 30 | # 该脚本会请求并执行当前项目下的 `bin/install.sh` 31 | 32 | bash <(curl -fsSLk https://gitee.com/wtklbm/rust-library-chinese/raw/main/bin/install.sh) 33 | ``` 34 | 35 | ### 手动安装 36 | 37 | - 在使用中文文档时,请注意版本号,中文文档版本和 Rust 版本号必须要保持一致。 38 | - 必须使用 `stable` 版本的指定版本号,不能使用 `beta` 和 `nightly` 版本。 39 | - 在翻译后的源代码中,一些文档的底部会存在一定量的内容为空的注释行,其实这是有意为之,请不要擅自修改和删除。如果您删除了它,就会导致 `source-map` 失效,当 `source-map` 失效后,在调试源代码时就会出现执行位置和源代码位置不一致的严重问题。 40 | 41 | 最新的构建结果会放在 [`dist`](../dist) 目录下,您可以手动跳转到该文件夹,下载最新的构建结果。 42 | 43 | 如果您是刚开始使用 Rust,那么请确保 Rust 已经安装好,并且可以正常工作。在 Rust 安装成功后,您还应该通过 `rustup component add rust-src` 命令来安装 `rust-src` 组件。当安装 `rust-src` 组件之后,请按照以下步骤进行操作: 44 | 45 | 1. 在终端执行:`rustup default stable` 来切换到 `stable` 版本,并确保 `stable` 的版本与中文版文档所对应的版本一致 46 | 2. 在终端执行 `rustup show home`,在输出中找到所对应的路径,然后将其在资源管理器中打开 47 | 3. 打开 `toolchains` 的文件夹,在该文件夹下,找到您当前所使用的 Rust 工具链并将其打开,例如,在 `Windows` 平台上对应的是 `stable-x86_64-pc-windows-msvc` 文件夹 48 | 4. 然后打开 `lib/rustlib/src/rust` 目录,这个目录下的文件夹就是 Rust 标准库源代码所在的位置 49 | 5. 将 `lib/rustlib/src/rust/library` 文件夹下的所有内容保存一份副本 50 | 6. 下载本仓库对应的中文文档源文件,将其重命名为 `library` 并放置到 `lib/rustlib/src/rust` 文件夹下 51 | 7. 请确保您已经在 IDE 中安装 Rust 相关插件,例如: 52 | - Visual Studio Code 需要安装 [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer) 53 | - JetBrains 系列需要安装 [Rust](https://plugins.jetbrains.com/plugin/8182-rust) 54 | 8. 重新启动 `IDE` 工具,中文文档的智能提示开始工作 55 | 9. 愉快的编码! 56 | 57 | ## 卸载中文文档 58 | 59 | ```bash 60 | # 在终端执行 61 | 62 | rustup component remove rust-src 63 | rustup component add rust-src 64 | ``` 65 | -------------------------------------------------------------------------------- /docs/assets/2021-12-17_19.31.02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtklbm/rust-library-i18n/49f8ccc483bcbc6cf915ad712a25fc9103911043/docs/assets/2021-12-17_19.31.02.png -------------------------------------------------------------------------------- /docs/assets/2021-12-17_20.10.20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtklbm/rust-library-i18n/49f8ccc483bcbc6cf915ad712a25fc9103911043/docs/assets/2021-12-17_20.10.20.png -------------------------------------------------------------------------------- /docs/assets/2021-12-17_20.19.25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wtklbm/rust-library-i18n/49f8ccc483bcbc6cf915ad712a25fc9103911043/docs/assets/2021-12-17_20.19.25.png --------------------------------------------------------------------------------