mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-26 00:11:49 +02:00
Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c923e7af73 | ||
|
|
c838d446ad | ||
|
|
50323a3977 | ||
|
|
7b5ef323c5 | ||
|
|
199150fda2 | ||
|
|
c1b5a0511f | ||
|
|
742200d14b | ||
|
|
900d58d054 | ||
|
|
6af86bbf22 | ||
|
|
4c1070faab | ||
|
|
f437f8e9ea | ||
|
|
c9c743967f | ||
|
|
88c9a23884 | ||
|
|
1d5700e58a | ||
|
|
96552e07c2 | ||
|
|
c97e659d78 | ||
|
|
291da61fda | ||
|
|
94bdb708fe | ||
|
|
3309a01b5e | ||
|
|
5a03e46d69 | ||
|
|
bf95a34553 | ||
|
|
33e501981a | ||
|
|
4ee9a0f6b9 | ||
|
|
d6e26bb350 | ||
|
|
f6a37e28ba | ||
|
|
a2f66e6a67 | ||
|
|
b92e7b968f | ||
|
|
6c2630afcf | ||
|
|
86506fa5fd | ||
|
|
96098d228a | ||
|
|
d59dde320b | ||
|
|
fb7d3bf35d | ||
|
|
50272a58e2 | ||
|
|
93f60d3f8d | ||
|
|
97bf2469b6 | ||
|
|
2088dfbaf6 | ||
|
|
e889c5bb60 | ||
|
|
44d609816b | ||
|
|
99ea2cbba7 | ||
|
|
0aff5340b5 | ||
|
|
6f44cb1dd2 | ||
|
|
52a29aa84b | ||
|
|
d0c7b06eff | ||
|
|
5f9dd129ea | ||
|
|
34392662a6 | ||
|
|
3c1fe226f0 | ||
|
|
3ac002934d | ||
|
|
4455c22b9a | ||
|
|
714a8075cc | ||
|
|
0a9d34a25a | ||
|
|
bb6b9e1704 | ||
|
|
8a4ed70762 | ||
|
|
1c3b003c7c | ||
|
|
25ab52b8e7 | ||
|
|
cd0ee50dd7 | ||
|
|
2f2f141564 | ||
|
|
4400ce2892 | ||
|
|
cc1b22d45f | ||
|
|
e8122daa87 | ||
|
|
8dfffe8aa2 | ||
|
|
f107e2f31d | ||
|
|
cf813b707c | ||
|
|
2b0c73c7e4 | ||
|
|
3c84cc1702 | ||
|
|
57377e8bf7 | ||
|
|
a16e7b918a | ||
|
|
7e1a4c0363 | ||
|
|
cfbce9d225 | ||
|
|
c1c4f86317 | ||
|
|
dcf4efe628 | ||
|
|
26b347a8bd | ||
|
|
3c85fc4d39 | ||
|
|
a7ca40d8a3 | ||
|
|
8d9df94b6c | ||
|
|
bf84fe029f | ||
|
|
ca96e32ff7 | ||
|
|
ef70ad907f | ||
|
|
f25f77e915 | ||
|
|
a0a06232ce | ||
|
|
300cdc27dd | ||
|
|
7a7281764c | ||
|
|
d27c12e35d | ||
|
|
cbf9016187 | ||
|
|
6ac42c5141 | ||
|
|
6289238d1d | ||
|
|
e3b65186fd | ||
|
|
affc815447 | ||
|
|
af301a2efe | ||
|
|
977a167335 | ||
|
|
08f42761f9 | ||
|
|
a04d62372f | ||
|
|
5a8f2b62e3 | ||
|
|
c5ecc37a9a | ||
|
|
a56f648cce | ||
|
|
a3a5fbeddf | ||
|
|
3963559810 | ||
|
|
4bee3399f8 | ||
|
|
32687cc66e | ||
|
|
d21a8e63c1 | ||
|
|
72e21a2a6c | ||
|
|
301bc52857 | ||
|
|
f88c7d1e8c | ||
|
|
3a327096c6 | ||
|
|
7a6079b46a | ||
|
|
c1fc77e50f | ||
|
|
cbca27dffe | ||
|
|
5cb40b2c95 | ||
|
|
e0fb7e72bb | ||
|
|
e858fd94fb | ||
|
|
56c05f6232 | ||
|
|
2663cc8e80 | ||
|
|
2356b5c1b6 | ||
|
|
e9f5c9423c | ||
|
|
f34d390bba | ||
|
|
fb7dac75a7 | ||
|
|
f9413b8ae1 | ||
|
|
fef10b8a0f | ||
|
|
82c41a61b6 | ||
|
|
3b74f5dae8 | ||
|
|
316fc58b4c | ||
|
|
8a4dca5fa6 | ||
|
|
4910bae10f | ||
|
|
0e7de2e7a7 | ||
|
|
e1d6abb4c9 | ||
|
|
02d78c3e84 | ||
|
|
727fc3037c | ||
|
|
1aecf32748 | ||
|
|
2f113b9b06 | ||
|
|
d46a97ef97 | ||
|
|
7035d6787c | ||
|
|
ce86d252e5 | ||
|
|
8a0c6cfcfa | ||
|
|
b0e070c743 | ||
|
|
ab291a1fcd | ||
|
|
3bb008ebbb | ||
|
|
e8cf9b2628 | ||
|
|
179202a34a | ||
|
|
55900c65cb |
@@ -1371,6 +1371,204 @@
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "wojexe",
|
||||
"name": "wojexe",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/21208490?v=4",
|
||||
"profile": "https://wojexe.com",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Tostapunk",
|
||||
"name": "Mattia Schiavon",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/25140297?v=4",
|
||||
"profile": "https://github.com/Tostapunk",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "PrettyWood",
|
||||
"name": "Eric Jolibois",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/18406791?v=4",
|
||||
"profile": "http://toucantoco.com",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "EdwinChang24",
|
||||
"name": "Edwin Chang",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/88263098?v=4",
|
||||
"profile": "http://edwinchang.vercel.app",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "saikatdas0790",
|
||||
"name": "Saikat Das",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7412443?v=4",
|
||||
"profile": "https://saikat.dev/",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "thatlittleboy",
|
||||
"name": "Jeremy Goh",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/30731072?v=4",
|
||||
"profile": "https://github.com/thatlittleboy",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Lioness100",
|
||||
"name": "Lioness100",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/65814829?v=4",
|
||||
"profile": "https://github.com/Lioness100",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "tvkn",
|
||||
"name": "Tristan Nicholls",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/79277926?v=4",
|
||||
"profile": "https://github.com/tvkn",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "clairew",
|
||||
"name": "Claire",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/9344258?v=4",
|
||||
"profile": "http://clairewang.net",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Mouwrice",
|
||||
"name": "Maurice Van Wassenhove",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/56763273?v=4",
|
||||
"profile": "https://github.com/Mouwrice",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "johnmendel",
|
||||
"name": "John Mendelewski",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/77524?v=4",
|
||||
"profile": "http://jmthree.com",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "brianfakhoury",
|
||||
"name": "Brian Fakhoury",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/20828724?v=4",
|
||||
"profile": "http://fakhoury.xyz",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "markusboehme",
|
||||
"name": "Markus Boehme",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/5074759?v=4",
|
||||
"profile": "https://github.com/markusboehme",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "nico-vromans",
|
||||
"name": "Nico Vromans",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/48183857?v=4",
|
||||
"profile": "https://github.com/nico-vromans",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "vostok92",
|
||||
"name": "vostok92",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/540339?v=4",
|
||||
"profile": "https://github.com/vostok92",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "magnusrodseth",
|
||||
"name": "Magnus Rødseth",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/59113973?v=4",
|
||||
"profile": "http://magnusrodseth.vercel.app",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "rubiesonthesky",
|
||||
"name": "rubiesonthesky",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/2591240?v=4",
|
||||
"profile": "https://github.com/rubiesonthesky",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "GabrielBianconi",
|
||||
"name": "Gabriel Bianconi",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1275491?v=4",
|
||||
"profile": "http://www.gabrielbianconi.com/",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Kodylow",
|
||||
"name": "Kody Low",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/74332828?v=4",
|
||||
"profile": "https://github.com/Kodylow",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "rzrymiak",
|
||||
"name": "rzrymiak",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/106121613?v=4",
|
||||
"profile": "https://github.com/rzrymiak",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "miguelraz",
|
||||
"name": "Miguel Raz Guzmán Macedo",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/13056181?v=4",
|
||||
"profile": "https://github.com/miguelraz",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "memark",
|
||||
"name": "Magnus Markling",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/318504?v=4",
|
||||
"profile": "https://github.com/memark",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 8,
|
||||
|
||||
@@ -2,6 +2,6 @@ root = true
|
||||
|
||||
[*.rs]
|
||||
end_of_line = lf
|
||||
insert_final_newfile = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
28
AUTHORS.md
28
AUTHORS.md
@@ -195,6 +195,34 @@ authors.
|
||||
<td align="center"><a href="https://jamesabromley.wordpress.com/"><img src="https://avatars.githubusercontent.com/u/2474334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>James Bromley</b></sub></a><br /><a href="#content-jayber" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/swhiteCQC"><img src="https://avatars.githubusercontent.com/u/77438466?v=4?s=100" width="100px;" alt=""/><br /><sub><b>swhiteCQC</b></sub></a><br /><a href="#content-swhiteCQC" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/neilpate"><img src="https://avatars.githubusercontent.com/u/7802334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Neil Pate</b></sub></a><br /><a href="#content-neilpate" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://wojexe.com"><img src="https://avatars.githubusercontent.com/u/21208490?v=4?s=100" width="100px;" alt=""/><br /><sub><b>wojexe</b></sub></a><br /><a href="#content-wojexe" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/Tostapunk"><img src="https://avatars.githubusercontent.com/u/25140297?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mattia Schiavon</b></sub></a><br /><a href="#content-Tostapunk" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://toucantoco.com"><img src="https://avatars.githubusercontent.com/u/18406791?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Eric Jolibois</b></sub></a><br /><a href="#content-PrettyWood" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="http://edwinchang.vercel.app"><img src="https://avatars.githubusercontent.com/u/88263098?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Edwin Chang</b></sub></a><br /><a href="#content-EdwinChang24" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://saikat.dev/"><img src="https://avatars.githubusercontent.com/u/7412443?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Saikat Das</b></sub></a><br /><a href="#content-saikatdas0790" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/thatlittleboy"><img src="https://avatars.githubusercontent.com/u/30731072?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeremy Goh</b></sub></a><br /><a href="#content-thatlittleboy" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="#content-Lioness100" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/tvkn"><img src="https://avatars.githubusercontent.com/u/79277926?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tristan Nicholls</b></sub></a><br /><a href="#content-tvkn" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://clairewang.net"><img src="https://avatars.githubusercontent.com/u/9344258?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Claire</b></sub></a><br /><a href="#content-clairew" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/Mouwrice"><img src="https://avatars.githubusercontent.com/u/56763273?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maurice Van Wassenhove</b></sub></a><br /><a href="#content-Mouwrice" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://jmthree.com"><img src="https://avatars.githubusercontent.com/u/77524?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John Mendelewski</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=johnmendel" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="http://fakhoury.xyz"><img src="https://avatars.githubusercontent.com/u/20828724?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Brian Fakhoury</b></sub></a><br /><a href="#content-brianfakhoury" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/markusboehme"><img src="https://avatars.githubusercontent.com/u/5074759?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Markus Boehme</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=markusboehme" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/nico-vromans"><img src="https://avatars.githubusercontent.com/u/48183857?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nico Vromans</b></sub></a><br /><a href="#content-nico-vromans" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/vostok92"><img src="https://avatars.githubusercontent.com/u/540339?v=4?s=100" width="100px;" alt=""/><br /><sub><b>vostok92</b></sub></a><br /><a href="#content-vostok92" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://magnusrodseth.vercel.app"><img src="https://avatars.githubusercontent.com/u/59113973?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Magnus Rødseth</b></sub></a><br /><a href="#content-magnusrodseth" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/rubiesonthesky"><img src="https://avatars.githubusercontent.com/u/2591240?v=4?s=100" width="100px;" alt=""/><br /><sub><b>rubiesonthesky</b></sub></a><br /><a href="#content-rubiesonthesky" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://www.gabrielbianconi.com/"><img src="https://avatars.githubusercontent.com/u/1275491?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gabriel Bianconi</b></sub></a><br /><a href="#content-GabrielBianconi" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/Kodylow"><img src="https://avatars.githubusercontent.com/u/74332828?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kody Low</b></sub></a><br /><a href="#content-Kodylow" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/rzrymiak"><img src="https://avatars.githubusercontent.com/u/106121613?v=4?s=100" width="100px;" alt=""/><br /><sub><b>rzrymiak</b></sub></a><br /><a href="#content-rzrymiak" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/miguelraz"><img src="https://avatars.githubusercontent.com/u/13056181?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Miguel Raz Guzmán Macedo</b></sub></a><br /><a href="#content-miguelraz" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/memark"><img src="https://avatars.githubusercontent.com/u/318504?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Magnus Markling</b></sub></a><br /><a href="#content-memark" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
73
CHANGELOG.md
73
CHANGELOG.md
@@ -1,3 +1,76 @@
|
||||
<a name="5.2.1"></a>
|
||||
## 5.2.1 (2022-09-06)
|
||||
|
||||
#### Fixed
|
||||
|
||||
- **quiz1**: Reworded the comment to actually reflect what's going on in the tests.
|
||||
Also added another assert just to make sure.
|
||||
- **rc1**: Fixed a typo in the hint.
|
||||
- **lifetimes**: Add quotes to the `println!` output, for readability.
|
||||
|
||||
#### Housekeeping
|
||||
|
||||
- Fixed a typo in README.md
|
||||
|
||||
<a name="5.2.0"></a>
|
||||
## 5.2.0 (2022-08-27)
|
||||
|
||||
#### Added
|
||||
|
||||
- Added a `reset` command
|
||||
|
||||
#### Changed
|
||||
|
||||
- **options2**: Convert the exercise to use tests
|
||||
|
||||
#### Fixed
|
||||
|
||||
- **threads3**: Fixed a typo
|
||||
- **quiz1**: Adjusted the explanations to be consistent with
|
||||
the tests
|
||||
|
||||
<a name="5.1.1"></a>
|
||||
## 5.1.1 (2022-08-17)
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
- Fixed an incorrect assertion in options1
|
||||
|
||||
<a name="5.1.0"></a>
|
||||
## 5.1.0 (2022-08-16)
|
||||
|
||||
#### Features
|
||||
|
||||
- Added a new `rc1` exercise.
|
||||
- Added a new `cow1` exercise.
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
- **variables5**: Corrected reference to previous exercise
|
||||
- **functions4**: Fixed line number reference
|
||||
- **strings3**: Clarified comment wording
|
||||
- **traits4, traits5**: Fixed line number reference
|
||||
- **traits5**:
|
||||
- Fixed typo in "parameter"
|
||||
- Made exercise prefer a traits-based solution
|
||||
- **lifetimes2**: Improved hint
|
||||
- **threads3**: Fixed typo in hint
|
||||
- **box1**: Replaced `unimplemented!` with `todo!`
|
||||
- **errors5**: Provided an explanation for usage of `Box<dyn Error>`
|
||||
- **quiz2**: Fixed a typo
|
||||
- **macros**: Updated the macros book link
|
||||
- **options1**:
|
||||
- Removed unused code
|
||||
- Added more granular tests
|
||||
- Fixed some comment syntax shenanigans in info.toml
|
||||
|
||||
#### Housekeeping
|
||||
|
||||
- Fixed a typo in .editorconfig
|
||||
- Fixed a typo in integration_tests.rs
|
||||
- Clarified manual installation instructions using `cargo install --path .`
|
||||
- Added a link to our Zulip in the readme file
|
||||
|
||||
<a name="5.0.0"></a>
|
||||
## 5.0.0 (2022-07-16)
|
||||
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -459,7 +459,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "rustlings"
|
||||
version = "4.8.0"
|
||||
version = "5.2.1"
|
||||
dependencies = [
|
||||
"argh",
|
||||
"assert_cmd",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rustlings"
|
||||
version = "5.0.0"
|
||||
version = "5.2.1"
|
||||
authors = ["Liv <mokou@fastmail.com>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
|
||||
12
README.md
12
README.md
@@ -54,11 +54,11 @@ If you get a permission denied message, you might have to exclude the directory
|
||||
|
||||
## Manually
|
||||
|
||||
Basically: Clone the repository at the latest tag, run `cargo install`.
|
||||
Basically: Clone the repository at the latest tag, run `cargo install --path .`.
|
||||
|
||||
```bash
|
||||
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.0.0)
|
||||
git clone -b 5.0.0 --depth 1 https://github.com/rust-lang/rustlings
|
||||
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.2.1)
|
||||
git clone -b 5.2.1 --depth 1 https://github.com/rust-lang/rustlings
|
||||
cd rustlings
|
||||
cargo install --force --path .
|
||||
```
|
||||
@@ -134,7 +134,7 @@ Once you've completed Rustlings, put your new knowledge to good use! Continue pr
|
||||
|
||||
## Uninstalling Rustlings
|
||||
|
||||
If you want to remove Rustlings from your system, there's two steps. First, you'll need to remove the exercises folder that the install script created
|
||||
If you want to remove Rustlings from your system, there are two steps. First, you'll need to remove the exercises folder that the install script created
|
||||
for you:
|
||||
|
||||
```bash
|
||||
@@ -154,6 +154,10 @@ Now you should be done!
|
||||
|
||||
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
||||
|
||||
Development-focused discussion about Rustlings happens in the [**rustlings** stream](https://rust-lang.zulipchat.com/#narrow/stream/334454-rustlings)
|
||||
on the [Rust Project Zulip](https://rust-lang.zulipchat.com). Feel free to start a new thread there
|
||||
if you have ideas or suggestions!
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to the wonderful people listed in [AUTHORS.md](./AUTHORS.md) 🎉
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
// This exercise uses some concepts that we won't get to until later in the course, like `Box` and the
|
||||
// `From` trait. It's not important to understand them in detail right now, but you can read ahead if you like.
|
||||
// For now, think of the `Box<dyn ...>` type as an "I want anything that does ???" type, which, given
|
||||
// Rust's usual standards for runtime safety, should strike you as somewhat lenient!
|
||||
|
||||
// In short, this particular use case for boxes is for when you want to own a value and you care only that it is a
|
||||
// type which implements a particular trait. To do so, The Box is declared as of type Box<dyn Trait> where Trait is the trait
|
||||
|
||||
@@ -22,5 +22,5 @@ fn main() {
|
||||
let string2 = "xyz";
|
||||
|
||||
let result = longest(string1.as_str(), string2);
|
||||
println!("The longest string is {}", result);
|
||||
println!("The longest string is '{}'", result);
|
||||
}
|
||||
|
||||
@@ -23,5 +23,5 @@ fn main() {
|
||||
let string2 = String::from("xyz");
|
||||
result = longest(string1.as_str(), string2.as_str());
|
||||
}
|
||||
println!("The longest string is {}", result);
|
||||
println!("The longest string is '{}'", result);
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ macros. Instead, we'll show you how to use and create them.
|
||||
## Further information
|
||||
|
||||
- [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html)
|
||||
- [The Little Book of Rust Macros](https://danielkeep.github.io/tlborm/book/index.html)
|
||||
- [The Little Book of Rust Macros](https://veykril.github.io/tlborm/)
|
||||
|
||||
@@ -3,17 +3,13 @@
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// you can modify anything EXCEPT for this function's signature
|
||||
fn print_number(maybe_number: Option<u16>) {
|
||||
println!("printing: {}", maybe_number.unwrap());
|
||||
}
|
||||
|
||||
// This function returns how much icecream there is left in the fridge.
|
||||
// If it's before 10PM, there's 5 pieces left. At 10PM, someone eats them
|
||||
// all, so there'll be no more left :(
|
||||
// TODO: Return an Option!
|
||||
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
|
||||
// We use the 24-hour system here, so 10PM is a value of 22
|
||||
// The Option output should gracefully handle cases where time_of_day > 24.
|
||||
???
|
||||
}
|
||||
|
||||
@@ -23,9 +19,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn check_icecream() {
|
||||
assert_eq!(maybe_icecream(9), Some(5));
|
||||
assert_eq!(maybe_icecream(10), Some(5));
|
||||
assert_eq!(maybe_icecream(23), None);
|
||||
assert_eq!(maybe_icecream(22), None);
|
||||
assert_eq!(maybe_icecream(23), Some(0));
|
||||
assert_eq!(maybe_icecream(22), Some(0));
|
||||
assert_eq!(maybe_icecream(25), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -3,23 +3,34 @@
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let optional_word = Some(String::from("rustlings"));
|
||||
// TODO: Make this an if let statement whose value is "Some" type
|
||||
word = optional_word {
|
||||
println!("The word is: {}", word);
|
||||
} else {
|
||||
println!("The optional word doesn't contain anything");
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn simple_option() {
|
||||
let target = "rustlings";
|
||||
let optional_target = Some(target);
|
||||
|
||||
// TODO: Make this an if let statement whose value is "Some" type
|
||||
word = optional_target {
|
||||
assert_eq!(word, target);
|
||||
}
|
||||
}
|
||||
|
||||
let mut optional_integers_vec: Vec<Option<i8>> = Vec::new();
|
||||
for x in 1..10 {
|
||||
optional_integers_vec.push(Some(x));
|
||||
}
|
||||
#[test]
|
||||
fn layered_option() {
|
||||
let mut range = 10;
|
||||
let mut optional_integers: Vec<Option<i8>> = Vec::new();
|
||||
for i in 0..(range + 1) {
|
||||
optional_integers.push(Some(i));
|
||||
}
|
||||
|
||||
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
|
||||
// You can stack `Option<T>`'s into while let and if let
|
||||
integer = optional_integers_vec.pop() {
|
||||
println!("current value: {}", integer);
|
||||
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
|
||||
// You can stack `Option<T>`'s into while let and if let
|
||||
integer = optional_integers.pop() {
|
||||
assert_eq!(integer, range);
|
||||
range -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
// - Functions
|
||||
// - If
|
||||
|
||||
// Mary is buying apples. One apple usually costs 2 Rustbucks, but if you buy
|
||||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||
// the price of an order of apples given the quantity bought. No hints this time!
|
||||
// Mary is buying apples. The price of an apple is calculated as follows:
|
||||
// - An apple costs 2 rustbucks.
|
||||
// - If Mary buys more than 40 apples, each apple only costs 1 rustbuck!
|
||||
// Write a function that calculates the price of an order of apples given
|
||||
// the quantity bought. No hints this time!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@@ -18,9 +20,11 @@
|
||||
fn verify_test() {
|
||||
let price1 = calculate_price_of_apples(35);
|
||||
let price2 = calculate_price_of_apples(40);
|
||||
let price3 = calculate_price_of_apples(65);
|
||||
let price3 = calculate_price_of_apples(41);
|
||||
let price4 = calculate_price_of_apples(65);
|
||||
|
||||
assert_eq!(70, price1);
|
||||
assert_eq!(80, price2);
|
||||
assert_eq!(65, price3);
|
||||
assert_eq!(41, price3);
|
||||
assert_eq!(65, price4);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ mod my_module {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// TODO: What to we have to import to have `transformer` in scope?
|
||||
// TODO: What do we have to import to have `transformer` in scope?
|
||||
use ???;
|
||||
use super::Command;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// elements: the value of the current item and the next item. The last item is a value called `Nil`.
|
||||
//
|
||||
// Step 1: use a `Box` in the enum definition to make the code compile
|
||||
// Step 2: create both empty and non-empty cons lists by replacing `unimplemented!()`
|
||||
// Step 2: create both empty and non-empty cons lists by replacing `todo!()`
|
||||
//
|
||||
// Note: the tests should not be changed
|
||||
//
|
||||
@@ -33,11 +33,11 @@ fn main() {
|
||||
}
|
||||
|
||||
pub fn create_empty_list() -> List {
|
||||
unimplemented!()
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn create_non_empty_list() -> List {
|
||||
unimplemented!()
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
48
exercises/standard_library_types/cow1.rs
Normal file
48
exercises/standard_library_types/cow1.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// cow1.rs
|
||||
|
||||
// This exercise explores the Cow, or Clone-On-Write type.
|
||||
// Cow is a clone-on-write smart pointer.
|
||||
// It can enclose and provide immutable access to borrowed data, and clone the data lazily when mutation or ownership is required.
|
||||
// The type is designed to work with general borrowed data via the Borrow trait.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> {
|
||||
for i in 0..input.len() {
|
||||
let v = input[i];
|
||||
if v < 0 {
|
||||
// Clones into a vector if not already owned.
|
||||
input.to_mut()[i] = -v;
|
||||
}
|
||||
}
|
||||
input
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// No clone occurs because `input` doesn't need to be mutated.
|
||||
let slice = [0, 1, 2];
|
||||
let mut input = Cow::from(&slice[..]);
|
||||
match abs_all(&mut input) {
|
||||
Cow::Borrowed(_) => println!("I borrowed the slice!"),
|
||||
_ => panic!("expected borrowed value"),
|
||||
}
|
||||
|
||||
// Clone occurs because `input` needs to be mutated.
|
||||
let slice = [-1, 0, 1];
|
||||
let mut input = Cow::from(&slice[..]);
|
||||
match abs_all(&mut input) {
|
||||
Cow::Owned(_) => println!("I modified the slice and now own it!"),
|
||||
_ => panic!("expected owned value"),
|
||||
}
|
||||
|
||||
// No clone occurs because `input` is already owned.
|
||||
let slice = vec![-1, 0, 1];
|
||||
let mut input = Cow::from(slice);
|
||||
match abs_all(&mut input) {
|
||||
// TODO
|
||||
Cow::Borrowed(_) => println!("I own this slice!"),
|
||||
_ => panic!("expected borrowed value"),
|
||||
}
|
||||
}
|
||||
98
exercises/standard_library_types/rc1.rs
Normal file
98
exercises/standard_library_types/rc1.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
// rc1.rs
|
||||
// In this exercise, we want to express the concept of multiple owners via the Rc<T> type.
|
||||
// This is a model of our solar system - there is a Sun type and multiple Planets.
|
||||
// The Planets take ownership of the sun, indicating that they revolve around the sun.
|
||||
|
||||
// Make this code compile by using the proper Rc primitives to express that the sun has multiple owners.
|
||||
|
||||
// I AM NOT DONE
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Sun {}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Planet {
|
||||
Mercury(Rc<Sun>),
|
||||
Venus(Rc<Sun>),
|
||||
Earth(Rc<Sun>),
|
||||
Mars(Rc<Sun>),
|
||||
Jupiter(Rc<Sun>),
|
||||
Saturn(Rc<Sun>),
|
||||
Uranus(Rc<Sun>),
|
||||
Neptune(Rc<Sun>),
|
||||
}
|
||||
|
||||
impl Planet {
|
||||
fn details(&self) {
|
||||
println!("Hi from {:?}!", self)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sun = Rc::new(Sun {});
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference
|
||||
|
||||
let mercury = Planet::Mercury(Rc::clone(&sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 2 references
|
||||
mercury.details();
|
||||
|
||||
let venus = Planet::Venus(Rc::clone(&sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 3 references
|
||||
venus.details();
|
||||
|
||||
let earth = Planet::Earth(Rc::clone(&sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 4 references
|
||||
earth.details();
|
||||
|
||||
let mars = Planet::Mars(Rc::clone(&sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 5 references
|
||||
mars.details();
|
||||
|
||||
let jupiter = Planet::Jupiter(Rc::clone(&sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 6 references
|
||||
jupiter.details();
|
||||
|
||||
// TODO
|
||||
let saturn = Planet::Saturn(Rc::new(Sun {}));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 7 references
|
||||
saturn.details();
|
||||
|
||||
// TODO
|
||||
let uranus = Planet::Uranus(Rc::new(Sun {}));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 8 references
|
||||
uranus.details();
|
||||
|
||||
// TODO
|
||||
let neptune = Planet::Neptune(Rc::new(Sun {}));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 9 references
|
||||
neptune.details();
|
||||
|
||||
assert_eq!(Rc::strong_count(&sun), 9);
|
||||
|
||||
drop(neptune);
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 8 references
|
||||
|
||||
drop(uranus);
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 7 references
|
||||
|
||||
drop(saturn);
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 6 references
|
||||
|
||||
drop(jupiter);
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 5 references
|
||||
|
||||
drop(mars);
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 4 references
|
||||
|
||||
// TODO
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 3 references
|
||||
|
||||
// TODO
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 2 references
|
||||
|
||||
// TODO
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference
|
||||
|
||||
assert_eq!(Rc::strong_count(&sun), 1);
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// I AM NOT DONE
|
||||
|
||||
fn trim_me(input: &str) -> String {
|
||||
// TODO: Remove whitespace from the end of a string!
|
||||
// TODO: Remove whitespace from both ends of a string!
|
||||
???
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// traits4.rs
|
||||
//
|
||||
// Your task is to replace the '??' sections so the code compiles.
|
||||
// Don't change any line other than 21.
|
||||
// Don't change any line other than the marked one.
|
||||
// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
@@ -19,6 +19,7 @@ struct OtherSoftware {}
|
||||
impl Licensed for SomeSoftware {}
|
||||
impl Licensed for OtherSoftware {}
|
||||
|
||||
// YOU MAY ONLY CHANGE THE NEXT LINE
|
||||
fn compare_license_types(software: ??, software_two: ??) -> bool {
|
||||
software.licensing_info() == software_two.licensing_info()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// traits5.rs
|
||||
//
|
||||
// Your task is to replace the '??' sections so the code compiles.
|
||||
// Don't change any line other than 27.
|
||||
// Don't change any line other than the marked one.
|
||||
// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
@@ -18,15 +18,20 @@ pub trait OtherTrait {
|
||||
}
|
||||
}
|
||||
|
||||
struct SomeStruct {
|
||||
name: String,
|
||||
}
|
||||
struct SomeStruct {}
|
||||
struct OtherStruct {}
|
||||
|
||||
impl SomeTrait for SomeStruct {}
|
||||
impl OtherTrait for SomeStruct {}
|
||||
impl SomeTrait for OtherStruct {}
|
||||
impl OtherTrait for OtherStruct {}
|
||||
|
||||
// YOU MAY ONLY CHANGE THE NEXT LINE
|
||||
fn some_func(item: ??) -> bool {
|
||||
item.some_function() && item.other_function()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
some_func(SomeStruct {});
|
||||
some_func(OtherStruct {});
|
||||
}
|
||||
|
||||
46
info.toml
46
info.toml
@@ -63,7 +63,7 @@ name = "variables5"
|
||||
path = "exercises/variables/variables5.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
In variables3 we already learned how to make an immutable variable mutable
|
||||
In variables4 we already learned how to make an immutable variable mutable
|
||||
using a special keyword. Unfortunately this doesn't help us much in this exercise
|
||||
because we want to assign a different typed value to an existing variable. Sometimes
|
||||
you may also like to reuse existing variable names because you are just converting
|
||||
@@ -123,8 +123,8 @@ name = "functions4"
|
||||
path = "exercises/functions/functions4.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
The error message points to line 14 and says it expects a type after the
|
||||
`->`. This is where the function's return type should be-- take a look at
|
||||
The error message points to line 17 and says it expects a type after the
|
||||
`->`. This is where the function's return type should be -- take a look at
|
||||
the `is_even` function for an example!
|
||||
|
||||
Also: Did you figure out that, technically, u32 would be the more fitting type
|
||||
@@ -545,7 +545,7 @@ is the easiest, but how do you do it safely so that it doesn't panic in your fac
|
||||
[[exercises]]
|
||||
name = "options2"
|
||||
path = "exercises/options/options2.rs"
|
||||
mode = "compile"
|
||||
mode = "test"
|
||||
hint = """
|
||||
check out:
|
||||
https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html
|
||||
@@ -732,7 +732,7 @@ name = "traits5"
|
||||
path = "exercises/traits/traits5.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
To ensure a paramter implements multiple traits use the '+ syntax'. Try replacing the
|
||||
To ensure a parameter implements multiple traits use the '+ syntax'. Try replacing the
|
||||
'??' with 'impl <> + <>'.
|
||||
|
||||
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#specifying-multiple-trait-bounds-with-the--syntax
|
||||
@@ -746,7 +746,7 @@ path = "exercises/quiz3.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
To find the best solution to this challenge you're going to need to think back to your
|
||||
knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;""""
|
||||
knowledge of traits, specifically Trait Bound Syntax - you may also need this: `use std::fmt::Display;`."""
|
||||
|
||||
# TESTS
|
||||
|
||||
@@ -795,7 +795,10 @@ name = "lifetimes2"
|
||||
path = "exercises/lifetimes/lifetimes2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
What is the compiler checking? How could you change how long an owned variable lives?"""
|
||||
Remember that the generic lifetime 'a will get the concrete lifetime that is equal to the smaller of the lifetimes of x and y.
|
||||
You can take at least two paths to achieve the desired result while keeping the inner block:
|
||||
1. Move the string2 declaration to make it live as long as string1 (how is result declared?)
|
||||
2. Move println! into the inner block"""
|
||||
|
||||
[[exercises]]
|
||||
name = "lifetimes3"
|
||||
@@ -929,6 +932,31 @@ is too much of a struggle, consider reading through all of Chapter 16 in the boo
|
||||
https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "rc1"
|
||||
path = "exercises/standard_library_types/rc1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
This is a straightforward exercise to use the Rc<T> type. Each Planet has
|
||||
ownership of the Sun, and uses Rc::clone() to increment the reference count of the Sun.
|
||||
After using drop() to move the Planets out of scope individually, the reference count goes down.
|
||||
In the end the sun only has one reference again, to itself. See more at:
|
||||
https://doc.rust-lang.org/book/ch15-04-rc.html
|
||||
|
||||
* Unfortunately Pluto is no longer considered a planet :(
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "cow1"
|
||||
path = "exercises/standard_library_types/cow1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Since the vector is already owned, the `Cow` type doesn't need to clone it.
|
||||
|
||||
Checkout https://doc.rust-lang.org/std/borrow/enum.Cow.html for documentation
|
||||
on the `Cow` type.
|
||||
"""
|
||||
|
||||
# THREADS
|
||||
|
||||
[[exercises]]
|
||||
@@ -984,8 +1012,8 @@ hint = """
|
||||
An alternate way to handle concurrency between threads is to use
|
||||
a mpsc (multiple producer, single consumer) channel to communicate.
|
||||
With both a sending end and a receiving end, it's possible to
|
||||
send values in one thread and receieve them in another.
|
||||
Multiple producers are possibile by using clone() to create a duplicate
|
||||
send values in one thread and receive them in another.
|
||||
Multiple producers are possible by using clone() to create a duplicate
|
||||
of the original sending end.
|
||||
See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info.
|
||||
"""
|
||||
|
||||
77
src/main.rs
77
src/main.rs
@@ -1,6 +1,6 @@
|
||||
use crate::exercise::{Exercise, ExerciseList};
|
||||
use crate::project::RustAnalyzerProject;
|
||||
use crate::run::run;
|
||||
use crate::run::{reset, run};
|
||||
use crate::verify::verify;
|
||||
use argh::FromArgs;
|
||||
use console::Emoji;
|
||||
@@ -26,7 +26,7 @@ mod run;
|
||||
mod verify;
|
||||
|
||||
// In sync with crate version
|
||||
const VERSION: &str = "5.0.0";
|
||||
const VERSION: &str = "5.2.1";
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
|
||||
@@ -47,6 +47,7 @@ enum Subcommands {
|
||||
Verify(VerifyArgs),
|
||||
Watch(WatchArgs),
|
||||
Run(RunArgs),
|
||||
Reset(ResetArgs),
|
||||
Hint(HintArgs),
|
||||
List(ListArgs),
|
||||
Lsp(LspArgs),
|
||||
@@ -71,6 +72,15 @@ struct RunArgs {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
#[argh(subcommand, name = "reset")]
|
||||
/// Resets a single exercise using "git stash -- <filename>"
|
||||
struct ResetArgs {
|
||||
#[argh(positional)]
|
||||
/// the name of the exercise
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
#[argh(subcommand, name = "hint")]
|
||||
/// Returns a hint for the given exercise
|
||||
@@ -85,7 +95,6 @@ struct HintArgs {
|
||||
/// Enable rust-analyzer for exercises
|
||||
struct LspArgs {}
|
||||
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
#[argh(subcommand, name = "list")]
|
||||
/// Lists the exercises available in Rustlings
|
||||
@@ -164,7 +173,9 @@ fn main() {
|
||||
"Pending"
|
||||
};
|
||||
let solve_cond = {
|
||||
(e.looks_done() && subargs.solved) || (!e.looks_done() && subargs.unsolved) || (!subargs.solved && !subargs.unsolved)
|
||||
(e.looks_done() && subargs.solved)
|
||||
|| (!e.looks_done() && subargs.unsolved)
|
||||
|| (!subargs.solved && !subargs.unsolved)
|
||||
};
|
||||
if solve_cond && (filter_cond || subargs.filter.is_none()) {
|
||||
let line = if subargs.paths {
|
||||
@@ -205,6 +216,12 @@ fn main() {
|
||||
run(exercise, verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
Subcommands::Reset(subargs) => {
|
||||
let exercise = find_exercise(&subargs.name, &exercises);
|
||||
|
||||
reset(exercise).unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
Subcommands::Hint(subargs) => {
|
||||
let exercise = find_exercise(&subargs.name, &exercises);
|
||||
|
||||
@@ -212,7 +229,8 @@ fn main() {
|
||||
}
|
||||
|
||||
Subcommands::Verify(_subargs) => {
|
||||
verify(&exercises, (0, exercises.len()), verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
verify(&exercises, (0, exercises.len()), verbose)
|
||||
.unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
Subcommands::Lsp(_subargs) => {
|
||||
@@ -236,12 +254,18 @@ fn main() {
|
||||
|
||||
Subcommands::Watch(_subargs) => match watch(&exercises, verbose) {
|
||||
Err(e) => {
|
||||
println!("Error: Could not watch your progress. Error message was {:?}.", e);
|
||||
println!(
|
||||
"Error: Could not watch your progress. Error message was {:?}.",
|
||||
e
|
||||
);
|
||||
println!("Most likely you've run out of disk space or your 'inotify limit' has been reached.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
Ok(WatchStatus::Finished) => {
|
||||
println!("{emoji} All exercises completed! {emoji}", emoji = Emoji("🎉", "★"));
|
||||
println!(
|
||||
"{emoji} All exercises completed! {emoji}",
|
||||
emoji = Emoji("🎉", "★")
|
||||
);
|
||||
println!("\n{}\n", FENISH_LINE);
|
||||
}
|
||||
Ok(WatchStatus::Unfinished) => {
|
||||
@@ -252,8 +276,10 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>, should_quit: Arc<AtomicBool>) {
|
||||
fn spawn_watch_shell(
|
||||
failed_exercise_hint: &Arc<Mutex<Option<String>>>,
|
||||
should_quit: Arc<AtomicBool>,
|
||||
) {
|
||||
let failed_exercise_hint = Arc::clone(failed_exercise_hint);
|
||||
println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here.");
|
||||
thread::spawn(move || loop {
|
||||
@@ -290,16 +316,22 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>, should_q
|
||||
|
||||
fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise {
|
||||
if name.eq("next") {
|
||||
exercises.iter().find(|e| !e.looks_done()).unwrap_or_else(|| {
|
||||
println!("🎉 Congratulations! You have done all the exercises!");
|
||||
println!("🔚 There are no more exercises to do next!");
|
||||
std::process::exit(1)
|
||||
})
|
||||
exercises
|
||||
.iter()
|
||||
.find(|e| !e.looks_done())
|
||||
.unwrap_or_else(|| {
|
||||
println!("🎉 Congratulations! You have done all the exercises!");
|
||||
println!("🔚 There are no more exercises to do next!");
|
||||
std::process::exit(1)
|
||||
})
|
||||
} else {
|
||||
exercises.iter().find(|e| e.name == name).unwrap_or_else(|| {
|
||||
println!("No exercise found for '{}'!", name);
|
||||
std::process::exit(1)
|
||||
})
|
||||
exercises
|
||||
.iter()
|
||||
.find(|e| e.name == name)
|
||||
.unwrap_or_else(|| {
|
||||
println!("No exercise found for '{}'!", name);
|
||||
std::process::exit(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,8 +369,13 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
let filepath = b.as_path().canonicalize().unwrap();
|
||||
let pending_exercises = exercises
|
||||
.iter()
|
||||
.find(|e| filepath.ends_with(&e.path)).into_iter()
|
||||
.chain(exercises.iter().filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)));
|
||||
.find(|e| filepath.ends_with(&e.path))
|
||||
.into_iter()
|
||||
.chain(
|
||||
exercises
|
||||
.iter()
|
||||
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
|
||||
);
|
||||
let num_done = exercises.iter().filter(|e| e.looks_done()).count();
|
||||
clear_screen();
|
||||
match verify(pending_exercises, (num_done, exercises.len()), verbose) {
|
||||
|
||||
15
src/run.rs
15
src/run.rs
@@ -1,3 +1,5 @@
|
||||
use std::process::Command;
|
||||
|
||||
use crate::exercise::{Exercise, Mode};
|
||||
use crate::verify::test;
|
||||
use indicatif::ProgressBar;
|
||||
@@ -15,6 +17,19 @@ pub fn run(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Resets the exercise by stashing the changes.
|
||||
pub fn reset(exercise: &Exercise) -> Result<(), ()> {
|
||||
let command = Command::new("git")
|
||||
.args(["stash", "--"])
|
||||
.arg(&exercise.path)
|
||||
.spawn();
|
||||
|
||||
match command {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke the rust compiler on the path of the given exercise
|
||||
// and run the ensuing binary.
|
||||
// This is strictly for non-test binaries, so output is displayed
|
||||
|
||||
@@ -110,6 +110,27 @@ fn run_single_test_no_exercise() {
|
||||
.code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_single_exercise() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(&["reset", "intro1"])
|
||||
.assert()
|
||||
.code(0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_no_exercise() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.arg("reset")
|
||||
.assert()
|
||||
.code(1)
|
||||
.stderr(predicates::str::contains(
|
||||
"positional arguments not provided",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_hint_for_single_test() {
|
||||
Command::cargo_bin("rustlings")
|
||||
@@ -126,7 +147,7 @@ fn all_exercises_require_confirmation() {
|
||||
for exercise in glob("exercises/**/*.rs").unwrap() {
|
||||
let path = exercise.unwrap();
|
||||
if path.file_name().unwrap() == "mod.rs" {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
let source = {
|
||||
let mut file = File::open(&path).unwrap();
|
||||
@@ -176,7 +197,7 @@ fn run_single_test_success_with_output() {
|
||||
.current_dir("tests/fixture/success/")
|
||||
.assert()
|
||||
.code(0)
|
||||
.stdout(predicates::str::contains("THIS TEST TOO SHALL PAS"));
|
||||
.stdout(predicates::str::contains("THIS TEST TOO SHALL PASS"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -187,7 +208,7 @@ fn run_single_test_success_without_output() {
|
||||
.current_dir("tests/fixture/success/")
|
||||
.assert()
|
||||
.code(0)
|
||||
.stdout(predicates::str::contains("THIS TEST TOO SHALL PAS").not());
|
||||
.stdout(predicates::str::contains("THIS TEST TOO SHALL PASS").not());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user