Compare commits

..

No commits in common. "31c6314cf908b09d9bc375266322d124d20f9020" and "15a739c3b0f2c08facdc1a98cb9b1e485aa2f0c8" have entirely different histories.

7 changed files with 57 additions and 165 deletions

View File

@ -131,7 +131,7 @@ Then run `cargo doc --open` and see the results.
### Doc tests
The doc comments of `add_one` and `add_two` contain two example code blocks.
The doc comments of `add_one` and `add_tow` contain two example code blocks.
The examples can not only demonstrate how to use your library, but also running as test with `cargo test` command.

View File

@ -15,7 +15,7 @@ This is precisely the goal of this book, so, collecting relative resourses and r
Answers for above questions usually came with [`ripgrep`](https://github.com/BurntSushi/ripgrep), though I don't think it is a **small** project, but yes, go for it if you are not afraid to delve deep a bit.
### 2. Building a text editor
Tutorial [`https://www.flenker.blog/hecto/`](https://www.flenker.blog/hecto/) will lead you to build a text editor from scratch.
Tutorial [`https://www.philippflenker.com/hecto/`](https://www.philippflenker.com/hecto/) will lead you to build a text editor from scratch.
### 3. Ncspot
[Ncspot](https://github.com/hrkfdn/ncspot), a terminal Spotify client. Small, simple, well organized and async, it's good for learning.

View File

@ -1,44 +0,0 @@
#!/usr/bin/env bash
#
# Function:
# 1. Link solution page to each practice page where there is no solution link
# 2. Correct link address (i.e. non-corresponding address)
#
# Usage:
# locate in the project root directory and execute the file
#
# Tips:
# Use 'git diff' to show the change after executing this command
set -e # exit on error
SOLUTION_DIR="solutions"
ZH_DIR="zh-CN/src"
EN_DIR="en/src"
LINK_PREFIX="https://github.com/sunface/rust-by-practice/blob/master"
# create an array of the relative address of all markdown file about practice in both Chinese and English
read -ra markdown_files <<< "$(echo "${ZH_DIR}"/**/*.md "${EN_DIR}"/**/*.md)"
for mdfile in "${markdown_files[@]}"; do
# if the corresponding solution file exist, check whether the practice file contians a
# link to solution or not. If not, create a link
solution_file=$( sed "s#\(${ZH_DIR}\|${EN_DIR}\)#${SOLUTION_DIR}#g" <<< "${mdfile}" )
if [[ -f "${solution_file}" ]]; then # exist solution file
echo -n "${mdfile}"
correct_link="${LINK_PREFIX}/${solution_file}"
found=$(grep -Ei '^\s*>.*https://.*solution.*$' < "${mdfile}" || true)
if [[ -z "${found}" ]]; then # not found link
echo >> "${mdfile}" # some file ends without newline character
if [[ "${mdfile}" == "${ZH_DIR}"/* ]]; then # written in Chinese
echo "> 你可以在[这里](${correct_link})找到答案(在 solutions 路径下)" >> "${mdfile}"
elif [[ "${mdfile}" == "${EN_DIR}"/* ]]; then # written in English
echo "> You can find the solutions [here](${correct_link})(under the solutions path), but only use it when you need it :)" >> "${mdfile}"
fi
else # found link in file
# simply correct all matched links
sed -i 's#^\(.*\)>\(.*\)(https://[^)]*)\(.*\)solution\(.*\)$#\1>\2('"${correct_link}"')\3solution\4#' "${mdfile}"
fi
echo " --done"
fi
done

View File

@ -23,10 +23,11 @@ fn main() {
println!("{},{}",x,y);
}
```
```rust
fn main() {
let x = String::from("hello, world");
let y = x.as_str();
let x = 10;
let y = x;
println!("{},{}",x,y);
}
```

View File

@ -83,7 +83,8 @@ fn main() {
let mut x: i32 = 1;
x = 7;
// Shadowing and re-binding
let x = x;
let mut x = x;
x += 3;
let y = 4;

View File

@ -136,6 +136,15 @@ dependencies = [
"libc",
]
[[package]]
name = "instant"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d"
dependencies = [
"cfg-if",
]
[[package]]
name = "itoa"
version = "0.4.7"
@ -150,15 +159,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.139"
version = "0.2.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
[[package]]
name = "lock_api"
version = "0.4.6"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b"
checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb"
dependencies = [
"scopeguard",
]
@ -204,14 +213,33 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.5"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys 0.42.0",
"miow",
"ntapi",
"winapi",
]
[[package]]
name = "miow"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
dependencies = [
"winapi",
]
[[package]]
name = "ntapi"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
dependencies = [
"winapi",
]
[[package]]
@ -251,25 +279,27 @@ checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
[[package]]
name = "parking_lot"
version = "0.12.1"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.7"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"windows-sys 0.45.0",
"winapi",
]
[[package]]
@ -426,16 +456,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
[[package]]
name = "socket2"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "strsim"
version = "0.8.0"
@ -497,28 +517,29 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.18.5"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e050c618355082ae5a89ec63bbf897225d5ffe84c7c4e036874e4d185a5044e"
checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi",
]
[[package]]
name = "tokio-macros"
version = "1.8.2"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110"
dependencies = [
"proc-macro2",
"quote",
@ -651,12 +672,6 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
@ -678,84 +693,3 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"

View File

@ -1,6 +1,6 @@
# Summary
- [关于 practice.rs](why-exercise.md)
- [关于 pracitce.rs](why-exercise.md)
- [值得学习的小型项目](elegant-code-base.md)
- [变量绑定与解构](variables.md)
- [基本类型](basic-types/intro.md)