Merge branch 'master' into exercise_ans

This commit is contained in:
ZhiHanZ 2020-05-04 02:21:59 -07:00 committed by GitHub
commit f0f9ea9915
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 853 additions and 68 deletions

465
.all-contributorsrc Normal file
View file

@ -0,0 +1,465 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "carols10cents",
"name": "Carol (Nichols || Goulding)",
"avatar_url": "https://avatars2.githubusercontent.com/u/193874?v=4",
"profile": "http://carol-nichols.com",
"contributions": [
"code",
"content"
]
},
{
"login": "QuietMisdreavus",
"name": "QuietMisdreavus",
"avatar_url": "https://avatars2.githubusercontent.com/u/5217170?v=4",
"profile": "https://twitter.com/QuietMisdreavus",
"contributions": [
"code",
"content"
]
},
{
"login": "robertlugg",
"name": "Robert M Lugg",
"avatar_url": "https://avatars0.githubusercontent.com/u/6054540?v=4",
"profile": "https://github.com/robertlugg",
"contributions": [
"content"
]
},
{
"login": "hynek",
"name": "Hynek Schlawack",
"avatar_url": "https://avatars3.githubusercontent.com/u/41240?v=4",
"profile": "https://hynek.me/about/",
"contributions": [
"code"
]
},
{
"login": "spacekookie",
"name": "Katharina Fey",
"avatar_url": "https://avatars0.githubusercontent.com/u/7669898?v=4",
"profile": "https://spacekookie.de",
"contributions": [
"code"
]
},
{
"login": "lukabavdaz",
"name": "lukabavdaz",
"avatar_url": "https://avatars0.githubusercontent.com/u/9624558?v=4",
"profile": "https://github.com/lukabavdaz",
"contributions": [
"code",
"content"
]
},
{
"login": "evestera",
"name": "Erik Vesteraas",
"avatar_url": "https://avatars2.githubusercontent.com/u/4187449?v=4",
"profile": "http://vestera.as",
"contributions": [
"code"
]
},
{
"login": "Delet0r",
"name": "delet0r",
"avatar_url": "https://avatars1.githubusercontent.com/u/23195618?v=4",
"profile": "https://github.com/Delet0r",
"contributions": [
"code"
]
},
{
"login": "shaunbennett",
"name": "Shaun Bennett",
"avatar_url": "https://avatars1.githubusercontent.com/u/10522375?v=4",
"profile": "http://phinary.ca",
"contributions": [
"code"
]
},
{
"login": "abagshaw",
"name": "Andrew Bagshaw",
"avatar_url": "https://avatars2.githubusercontent.com/u/8594541?v=4",
"profile": "https://github.com/abagshaw",
"contributions": [
"code"
]
},
{
"login": "kisom",
"name": "Kyle Isom",
"avatar_url": "https://avatars2.githubusercontent.com/u/175578?v=4",
"profile": "https://ai6ua.net/",
"contributions": [
"code"
]
},
{
"login": "ColinPitrat",
"name": "Colin Pitrat",
"avatar_url": "https://avatars3.githubusercontent.com/u/1541863?v=4",
"profile": "https://github.com/ColinPitrat",
"contributions": [
"code"
]
},
{
"login": "zacanger",
"name": "Zac Anger",
"avatar_url": "https://avatars3.githubusercontent.com/u/12520493?v=4",
"profile": "https://zacanger.com",
"contributions": [
"code"
]
},
{
"login": "mgeier",
"name": "Matthias Geier",
"avatar_url": "https://avatars1.githubusercontent.com/u/705404?v=4",
"profile": "https://github.com/mgeier",
"contributions": [
"code"
]
},
{
"login": "cjpearce",
"name": "Chris Pearce",
"avatar_url": "https://avatars1.githubusercontent.com/u/3453268?v=4",
"profile": "https://github.com/cjpearce",
"contributions": [
"code"
]
},
{
"login": "yvan-sraka",
"name": "Yvan Sraka",
"avatar_url": "https://avatars2.githubusercontent.com/u/705213?v=4",
"profile": "https://yvan-sraka.github.io",
"contributions": [
"code"
]
},
{
"login": "dendi239",
"name": "Denys Smirnov",
"avatar_url": "https://avatars3.githubusercontent.com/u/16478650?v=4",
"profile": "https://github.com/dendi239",
"contributions": [
"code"
]
},
{
"login": "eddyp",
"name": "eddyp",
"avatar_url": "https://avatars2.githubusercontent.com/u/123772?v=4",
"profile": "https://github.com/eddyp",
"contributions": [
"code"
]
},
{
"login": "briankung",
"name": "Brian Kung",
"avatar_url": "https://avatars1.githubusercontent.com/u/2836167?v=4",
"profile": "http://about.me/BrianKung",
"contributions": [
"code",
"content"
]
},
{
"login": "miller-time",
"name": "Russell",
"avatar_url": "https://avatars3.githubusercontent.com/u/281039?v=4",
"profile": "https://rcousineau.gitlab.io",
"contributions": [
"code"
]
},
{
"login": "danwilhelm",
"name": "Dan Wilhelm",
"avatar_url": "https://avatars3.githubusercontent.com/u/6137185?v=4",
"profile": "http://danwilhelm.com",
"contributions": [
"doc"
]
},
{
"login": "Jesse-Cameron",
"name": "Jesse",
"avatar_url": "https://avatars3.githubusercontent.com/u/3723654?v=4",
"profile": "https://github.com/Jesse-Cameron",
"contributions": [
"code",
"content"
]
},
{
"login": "MrFroop",
"name": "Fredrik Jambrén",
"avatar_url": "https://avatars3.githubusercontent.com/u/196700?v=4",
"profile": "https://github.com/MrFroop",
"contributions": [
"code"
]
},
{
"login": "petemcfarlane",
"name": "Pete McFarlane",
"avatar_url": "https://avatars3.githubusercontent.com/u/3472717?v=4",
"profile": "https://github.com/petemcfarlane",
"contributions": [
"content"
]
},
{
"login": "nkanderson",
"name": "nkanderson",
"avatar_url": "https://avatars0.githubusercontent.com/u/4128825?v=4",
"profile": "https://github.com/nkanderson",
"contributions": [
"code",
"content"
]
},
{
"login": "ajaxm",
"name": "Ajax M",
"avatar_url": "https://avatars0.githubusercontent.com/u/13360138?v=4",
"profile": "https://github.com/ajaxm",
"contributions": [
"doc"
]
},
{
"login": "Dylnuge",
"name": "Dylan Nugent",
"avatar_url": "https://avatars2.githubusercontent.com/u/118624?v=4",
"profile": "https://dylnuge.com",
"contributions": [
"content"
]
},
{
"login": "vyaslav",
"name": "vyaslav",
"avatar_url": "https://avatars0.githubusercontent.com/u/1385427?v=4",
"profile": "https://github.com/vyaslav",
"contributions": [
"code",
"content"
]
},
{
"login": "gdoenlen",
"name": "George",
"avatar_url": "https://avatars1.githubusercontent.com/u/17297466?v=4",
"profile": "https://join.sfxd.org",
"contributions": [
"code"
]
},
{
"login": "nyxtom",
"name": "Thomas Holloway",
"avatar_url": "https://avatars2.githubusercontent.com/u/222763?v=4",
"profile": "https://github.com/nyxtom",
"contributions": [
"code",
"content"
]
},
{
"login": "workingjubilee",
"name": "Jubilee",
"avatar_url": "https://avatars1.githubusercontent.com/u/46493976?v=4",
"profile": "https://github.com/workingjubilee",
"contributions": [
"code"
]
},
{
"login": "WofWca",
"name": "WofWca",
"avatar_url": "https://avatars1.githubusercontent.com/u/39462442?v=4",
"profile": "https://github.com/WofWca",
"contributions": [
"code"
]
},
{
"login": "jrvidal",
"name": "Roberto Vidal",
"avatar_url": "https://avatars0.githubusercontent.com/u/1636604?v=4",
"profile": "https://github.com/jrvidal",
"contributions": [
"code",
"doc",
"ideas",
"maintenance"
]
},
{
"login": "jensim",
"name": "Jens",
"avatar_url": "https://avatars0.githubusercontent.com/u/3663856?v=4",
"profile": "https://github.com/jensim",
"contributions": [
"doc"
]
},
{
"login": "rahatarmanahmed",
"name": "Rahat Ahmed",
"avatar_url": "https://avatars3.githubusercontent.com/u/3174006?v=4",
"profile": "http://rahatah.me/d",
"contributions": [
"doc"
]
},
{
"login": "AbdouSeck",
"name": "Abdou Seck",
"avatar_url": "https://avatars2.githubusercontent.com/u/6490055?v=4",
"profile": "https://github.com/AbdouSeck",
"contributions": [
"code",
"content",
"review"
]
},
{
"login": "codehearts",
"name": "Katie",
"avatar_url": "https://avatars0.githubusercontent.com/u/2885412?v=4",
"profile": "https://codehearts.com",
"contributions": [
"code"
]
},
{
"login": "Socratides",
"name": "Socrates",
"avatar_url": "https://avatars3.githubusercontent.com/u/27732983?v=4",
"profile": "https://github.com/Socratides",
"contributions": [
"doc"
]
},
{
"login": "gnodarse",
"name": "gnodarse",
"avatar_url": "https://avatars3.githubusercontent.com/u/46761795?v=4",
"profile": "https://github.com/gnodarse",
"contributions": [
"content"
]
},
{
"login": "harrisonmetz",
"name": "Harrison Metzger",
"avatar_url": "https://avatars1.githubusercontent.com/u/7883408?v=4",
"profile": "https://github.com/harrisonmetz",
"contributions": [
"code"
]
},
{
"login": "TorbenJ",
"name": "Torben Jonas",
"avatar_url": "https://avatars2.githubusercontent.com/u/9077102?v=4",
"profile": "https://github.com/TorbenJ",
"contributions": [
"code",
"content"
]
},
{
"login": "pbx",
"name": "Paul Bissex",
"avatar_url": "https://avatars0.githubusercontent.com/u/641?v=4",
"profile": "http://paulbissex.com/",
"contributions": [
"doc"
]
},
{
"login": "sjmann",
"name": "Steven Mann",
"avatar_url": "https://avatars0.githubusercontent.com/u/6589896?v=4",
"profile": "https://github.com/sjmann",
"contributions": [
"code",
"content"
]
},
{
"login": "Tarnadas",
"name": "Mario Reder",
"avatar_url": "https://avatars2.githubusercontent.com/u/5855071?v=4",
"profile": "https://smmdb.net/",
"contributions": [
"code",
"content"
]
},
{
"login": "sl4m",
"name": "skim",
"avatar_url": "https://avatars0.githubusercontent.com/u/47347?v=4",
"profile": "https://keybase.io/skim",
"contributions": [
"code"
]
},
{
"login": "sanjaykdragon",
"name": "Sanjay K",
"avatar_url": "https://avatars1.githubusercontent.com/u/10261698?v=4",
"profile": "https://github.com/sanjaykdragon",
"contributions": [
"code",
"content"
]
},
{
"login": "crodjer",
"name": "Rohan Jain",
"avatar_url": "https://avatars1.githubusercontent.com/u/343499?v=4",
"profile": "http://www.rohanjain.in",
"contributions": [
"code"
]
},
{
"login": "saidaspen",
"name": "Said Aspen",
"avatar_url": "https://avatars1.githubusercontent.com/u/7727687?v=4",
"profile": "https://www.saidaspen.se",
"contributions": [
"code",
"content"
]
}
],
"contributorsPerLine": 8,
"projectName": "rustlings",
"projectOwner": "fmoko",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
}

2
Cargo.lock generated
View file

@ -592,7 +592,7 @@ dependencies = [
[[package]]
name = "rustlings"
version = "2.2.1"
version = "3.0.0"
dependencies = [
"assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1,4 +1,7 @@
![crab pet](https://i.imgur.com/LbZJgmm.gif)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-48-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
# rustlings 🦀❤️ [![Build status](https://badge.buildkite.com/7af93d81dc522c67a1ec8e33ff5705861b1cb36360b774807f.svg)](https://buildkite.com/mokou/rustlings)
@ -15,8 +18,6 @@ Alternatively, for a first-time Rust learner, there's several other resources:
_Note: If you're on MacOS, make sure you've installed Xcode and its developer tools by typing `xcode-select --install`._
_Note: If you have Xcode 10+ installed, you also need to install the package file found at `/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg`._
You will need to have Rust installed. You can get it by visiting https://rustup.rs. This'll also install Cargo, Rust's package/project manager.
## MacOS/Linux
@ -122,7 +123,78 @@ If you are interested in improving or adding new ones, please feel free to contr
See [CONTRIBUTING.md](./CONTRIBUTING.md).
## Credits
## Contributors
`rustlings` was originally written by [Carol](https://github.com/carols10cents)!
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="http://carol-nichols.com"><img src="https://avatars2.githubusercontent.com/u/193874?v=4" width="100px;" alt=""/><br /><sub><b>Carol (Nichols &#124;&#124; Goulding)</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=carols10cents" title="Code">💻</a> <a href="#content-carols10cents" title="Content">🖋</a></td>
<td align="center"><a href="https://twitter.com/QuietMisdreavus"><img src="https://avatars2.githubusercontent.com/u/5217170?v=4" width="100px;" alt=""/><br /><sub><b>QuietMisdreavus</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=QuietMisdreavus" title="Code">💻</a> <a href="#content-QuietMisdreavus" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/robertlugg"><img src="https://avatars0.githubusercontent.com/u/6054540?v=4" width="100px;" alt=""/><br /><sub><b>Robert M Lugg</b></sub></a><br /><a href="#content-robertlugg" title="Content">🖋</a></td>
<td align="center"><a href="https://hynek.me/about/"><img src="https://avatars3.githubusercontent.com/u/41240?v=4" width="100px;" alt=""/><br /><sub><b>Hynek Schlawack</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=hynek" title="Code">💻</a></td>
<td align="center"><a href="https://spacekookie.de"><img src="https://avatars0.githubusercontent.com/u/7669898?v=4" width="100px;" alt=""/><br /><sub><b>Katharina Fey</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=spacekookie" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/lukabavdaz"><img src="https://avatars0.githubusercontent.com/u/9624558?v=4" width="100px;" alt=""/><br /><sub><b>lukabavdaz</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=lukabavdaz" title="Code">💻</a> <a href="#content-lukabavdaz" title="Content">🖋</a></td>
<td align="center"><a href="http://vestera.as"><img src="https://avatars2.githubusercontent.com/u/4187449?v=4" width="100px;" alt=""/><br /><sub><b>Erik Vesteraas</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=evestera" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Delet0r"><img src="https://avatars1.githubusercontent.com/u/23195618?v=4" width="100px;" alt=""/><br /><sub><b>delet0r</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Delet0r" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="http://phinary.ca"><img src="https://avatars1.githubusercontent.com/u/10522375?v=4" width="100px;" alt=""/><br /><sub><b>Shaun Bennett</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=shaunbennett" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/abagshaw"><img src="https://avatars2.githubusercontent.com/u/8594541?v=4" width="100px;" alt=""/><br /><sub><b>Andrew Bagshaw</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=abagshaw" title="Code">💻</a></td>
<td align="center"><a href="https://ai6ua.net/"><img src="https://avatars2.githubusercontent.com/u/175578?v=4" width="100px;" alt=""/><br /><sub><b>Kyle Isom</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=kisom" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ColinPitrat"><img src="https://avatars3.githubusercontent.com/u/1541863?v=4" width="100px;" alt=""/><br /><sub><b>Colin Pitrat</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=ColinPitrat" title="Code">💻</a></td>
<td align="center"><a href="https://zacanger.com"><img src="https://avatars3.githubusercontent.com/u/12520493?v=4" width="100px;" alt=""/><br /><sub><b>Zac Anger</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=zacanger" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/mgeier"><img src="https://avatars1.githubusercontent.com/u/705404?v=4" width="100px;" alt=""/><br /><sub><b>Matthias Geier</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=mgeier" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/cjpearce"><img src="https://avatars1.githubusercontent.com/u/3453268?v=4" width="100px;" alt=""/><br /><sub><b>Chris Pearce</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=cjpearce" title="Code">💻</a></td>
<td align="center"><a href="https://yvan-sraka.github.io"><img src="https://avatars2.githubusercontent.com/u/705213?v=4" width="100px;" alt=""/><br /><sub><b>Yvan Sraka</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=yvan-sraka" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/dendi239"><img src="https://avatars3.githubusercontent.com/u/16478650?v=4" width="100px;" alt=""/><br /><sub><b>Denys Smirnov</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=dendi239" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/eddyp"><img src="https://avatars2.githubusercontent.com/u/123772?v=4" width="100px;" alt=""/><br /><sub><b>eddyp</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=eddyp" title="Code">💻</a></td>
<td align="center"><a href="http://about.me/BrianKung"><img src="https://avatars1.githubusercontent.com/u/2836167?v=4" width="100px;" alt=""/><br /><sub><b>Brian Kung</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=briankung" title="Code">💻</a> <a href="#content-briankung" title="Content">🖋</a></td>
<td align="center"><a href="https://rcousineau.gitlab.io"><img src="https://avatars3.githubusercontent.com/u/281039?v=4" width="100px;" alt=""/><br /><sub><b>Russell</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=miller-time" title="Code">💻</a></td>
<td align="center"><a href="http://danwilhelm.com"><img src="https://avatars3.githubusercontent.com/u/6137185?v=4" width="100px;" alt=""/><br /><sub><b>Dan Wilhelm</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=danwilhelm" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/Jesse-Cameron"><img src="https://avatars3.githubusercontent.com/u/3723654?v=4" width="100px;" alt=""/><br /><sub><b>Jesse</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Jesse-Cameron" title="Code">💻</a> <a href="#content-Jesse-Cameron" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/MrFroop"><img src="https://avatars3.githubusercontent.com/u/196700?v=4" width="100px;" alt=""/><br /><sub><b>Fredrik Jambrén</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=MrFroop" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/petemcfarlane"><img src="https://avatars3.githubusercontent.com/u/3472717?v=4" width="100px;" alt=""/><br /><sub><b>Pete McFarlane</b></sub></a><br /><a href="#content-petemcfarlane" title="Content">🖋</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/nkanderson"><img src="https://avatars0.githubusercontent.com/u/4128825?v=4" width="100px;" alt=""/><br /><sub><b>nkanderson</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=nkanderson" title="Code">💻</a> <a href="#content-nkanderson" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/ajaxm"><img src="https://avatars0.githubusercontent.com/u/13360138?v=4" width="100px;" alt=""/><br /><sub><b>Ajax M</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=ajaxm" title="Documentation">📖</a></td>
<td align="center"><a href="https://dylnuge.com"><img src="https://avatars2.githubusercontent.com/u/118624?v=4" width="100px;" alt=""/><br /><sub><b>Dylan Nugent</b></sub></a><br /><a href="#content-Dylnuge" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/vyaslav"><img src="https://avatars0.githubusercontent.com/u/1385427?v=4" width="100px;" alt=""/><br /><sub><b>vyaslav</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=vyaslav" title="Code">💻</a> <a href="#content-vyaslav" title="Content">🖋</a></td>
<td align="center"><a href="https://join.sfxd.org"><img src="https://avatars1.githubusercontent.com/u/17297466?v=4" width="100px;" alt=""/><br /><sub><b>George</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=gdoenlen" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/nyxtom"><img src="https://avatars2.githubusercontent.com/u/222763?v=4" width="100px;" alt=""/><br /><sub><b>Thomas Holloway</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=nyxtom" title="Code">💻</a> <a href="#content-nyxtom" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/workingjubilee"><img src="https://avatars1.githubusercontent.com/u/46493976?v=4" width="100px;" alt=""/><br /><sub><b>Jubilee</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=workingjubilee" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/WofWca"><img src="https://avatars1.githubusercontent.com/u/39462442?v=4" width="100px;" alt=""/><br /><sub><b>WofWca</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=WofWca" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/jrvidal"><img src="https://avatars0.githubusercontent.com/u/1636604?v=4" width="100px;" alt=""/><br /><sub><b>Roberto Vidal</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=jrvidal" title="Code">💻</a> <a href="https://github.com/fmoko/rustlings/commits?author=jrvidal" title="Documentation">📖</a> <a href="#ideas-jrvidal" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-jrvidal" title="Maintenance">🚧</a></td>
<td align="center"><a href="https://github.com/jensim"><img src="https://avatars0.githubusercontent.com/u/3663856?v=4" width="100px;" alt=""/><br /><sub><b>Jens</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=jensim" title="Documentation">📖</a></td>
<td align="center"><a href="http://rahatah.me/d"><img src="https://avatars3.githubusercontent.com/u/3174006?v=4" width="100px;" alt=""/><br /><sub><b>Rahat Ahmed</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=rahatarmanahmed" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/AbdouSeck"><img src="https://avatars2.githubusercontent.com/u/6490055?v=4" width="100px;" alt=""/><br /><sub><b>Abdou Seck</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=AbdouSeck" title="Code">💻</a> <a href="#content-AbdouSeck" title="Content">🖋</a> <a href="https://github.com/fmoko/rustlings/pulls?q=is%3Apr+reviewed-by%3AAbdouSeck" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://codehearts.com"><img src="https://avatars0.githubusercontent.com/u/2885412?v=4" width="100px;" alt=""/><br /><sub><b>Katie</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=codehearts" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Socratides"><img src="https://avatars3.githubusercontent.com/u/27732983?v=4" width="100px;" alt=""/><br /><sub><b>Socrates</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Socratides" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/gnodarse"><img src="https://avatars3.githubusercontent.com/u/46761795?v=4" width="100px;" alt=""/><br /><sub><b>gnodarse</b></sub></a><br /><a href="#content-gnodarse" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/harrisonmetz"><img src="https://avatars1.githubusercontent.com/u/7883408?v=4" width="100px;" alt=""/><br /><sub><b>Harrison Metzger</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=harrisonmetz" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/TorbenJ"><img src="https://avatars2.githubusercontent.com/u/9077102?v=4" width="100px;" alt=""/><br /><sub><b>Torben Jonas</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=TorbenJ" title="Code">💻</a> <a href="#content-TorbenJ" title="Content">🖋</a></td>
<td align="center"><a href="http://paulbissex.com/"><img src="https://avatars0.githubusercontent.com/u/641?v=4" width="100px;" alt=""/><br /><sub><b>Paul Bissex</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=pbx" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/sjmann"><img src="https://avatars0.githubusercontent.com/u/6589896?v=4" width="100px;" alt=""/><br /><sub><b>Steven Mann</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=sjmann" title="Code">💻</a> <a href="#content-sjmann" title="Content">🖋</a></td>
<td align="center"><a href="https://smmdb.net/"><img src="https://avatars2.githubusercontent.com/u/5855071?v=4" width="100px;" alt=""/><br /><sub><b>Mario Reder</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Tarnadas" title="Code">💻</a> <a href="#content-Tarnadas" title="Content">🖋</a></td>
<td align="center"><a href="https://keybase.io/skim"><img src="https://avatars0.githubusercontent.com/u/47347?v=4" width="100px;" alt=""/><br /><sub><b>skim</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=sl4m" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/sanjaykdragon"><img src="https://avatars1.githubusercontent.com/u/10261698?v=4" width="100px;" alt=""/><br /><sub><b>Sanjay K</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=sanjaykdragon" title="Code">💻</a> <a href="#content-sanjaykdragon" title="Content">🖋</a></td>
<td align="center"><a href="http://www.rohanjain.in"><img src="https://avatars1.githubusercontent.com/u/343499?v=4" width="100px;" alt=""/><br /><sub><b>Rohan Jain</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=crodjer" title="Code">💻</a></td>
<td align="center"><a href="https://www.saidaspen.se"><img src="https://avatars1.githubusercontent.com/u/7727687?v=4" width="100px;" alt=""/><br /><sub><b>Said Aspen</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=saidaspen" title="Code">💻</a> <a href="#content-saidaspen" title="Content">🖋</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

View file

@ -2,6 +2,8 @@
// The Clippy tool is a collection of lints to analyze your code
// so you can catch common mistakes and improve your Rust code.
//
// For these exercises the code will fail to compile when there are clippy warnings
// check clippy's suggestions from the output to solve the exercise.
// Execute `rustlings hint clippy1` for hints :)
// I AM NOT DONE

View file

@ -29,9 +29,10 @@ impl Default for Person {
// 1. If the length of the provided string is 0, then return the default of Person
// 2. Split the given string on the commas present in it
// 3. Extract the first element from the split operation and use it as the name
// 4. Extract the other element from the split operation and parse it into a `usize` as the age
// 4. If the name is empty, then return the default of Person
// 5. Extract the other element from the split operation and parse it into a `usize` as the age
// If while parsing the age, something goes wrong, then return the default of Person
// Otherwise, then return an instantiated Person onject with the results
// Otherwise, then return an instantiated Person object with the results
impl From<&str> for Person {
fn from(s: &str) -> Person {
}
@ -77,4 +78,39 @@ mod tests {
assert_eq!(p.name, "John");
assert_eq!(p.age, 30);
}
#[test]
fn test_missing_comma_and_age() {
let p: Person = Person::from("Mark");
assert_eq!(p.name, "John");
assert_eq!(p.age, 30);
}
#[test]
fn test_missing_age() {
let p: Person = Person::from("Mark,");
assert_eq!(p.name, "John");
assert_eq!(p.age, 30);
}
#[test]
fn test_missing_name() {
let p: Person = Person::from(",1");
assert_eq!(p.name, "John");
assert_eq!(p.age, 30);
}
#[test]
fn test_missing_name_and_age() {
let p: Person = Person::from(",");
assert_eq!(p.name, "John");
assert_eq!(p.age, 30);
}
#[test]
fn test_missing_name_and_invalid_age() {
let p: Person = Person::from(",one");
assert_eq!(p.name, "John");
assert_eq!(p.age, 30);
}
}

View file

@ -15,7 +15,8 @@ struct Person {
// 1. If the length of the provided string is 0, then return an error
// 2. Split the given string on the commas present in it
// 3. Extract the first element from the split operation and use it as the name
// 4. Extract the other element from the split operation and parse it into a `usize` as the age
// 4. If the name is empty, then return an error
// 5. Extract the other element from the split operation and parse it into a `usize` as the age
// If while parsing the age, something goes wrong, then return an error
// Otherwise, then return a Result of a Person object
impl FromStr for Person {
@ -39,11 +40,46 @@ mod tests {
}
#[test]
fn good_input() {
assert!("John,32".parse::<Person>().is_ok());
let p = "John,32".parse::<Person>();
assert!(p.is_ok());
let p = p.unwrap();
assert_eq!(p.name, "John");
assert_eq!(p.age, 32);
}
#[test]
#[should_panic]
fn missing_age() {
"John,".parse::<Person>().unwrap();
}
#[test]
#[should_panic]
fn invalid_age() {
"John,twenty".parse::<Person>().unwrap();
}
#[test]
#[should_panic]
fn missing_comma_and_age() {
"John".parse::<Person>().unwrap();
}
#[test]
#[should_panic]
fn missing_name() {
",1".parse::<Person>().unwrap();
}
#[test]
#[should_panic]
fn missing_name_and_age() {
",".parse::<Person>().unwrap();
}
#[test]
#[should_panic]
fn missing_name_and_invalid_age() {
",one".parse::<Person>().unwrap();
}
}

View file

@ -22,7 +22,8 @@ struct Person {
// 1. If the length of the provided string is 0, then return an error
// 2. Split the given string on the commas present in it
// 3. Extract the first element from the split operation and use it as the name
// 4. Extract the other element from the split operation and parse it into a `usize` as the age
// 4. If the name is empty, then return an error.
// 5. Extract the other element from the split operation and parse it into a `usize` as the age
// If while parsing the age, something goes wrong, then return an error
// Otherwise, then return a Result of a Person object
impl TryFrom<&str> for Person {
@ -45,7 +46,7 @@ mod tests {
use super::*;
#[test]
fn test_bad_convert() {
// Test that John is returned when bad string is provided
// Test that error is returned when bad string is provided
let p = Person::try_from("");
assert!(p.is_err());
}
@ -68,4 +69,34 @@ mod tests {
fn test_panic_bad_age() {
let p = Person::try_from("Mark,twenty").unwrap();
}
#[test]
#[should_panic]
fn test_missing_comma_and_age() {
let _: Person = "Mark".try_into().unwrap();
}
#[test]
#[should_panic]
fn test_missing_age() {
let _: Person = "Mark,".try_into().unwrap();
}
#[test]
#[should_panic]
fn test_missing_name() {
let _ : Person = ",1".try_into().unwrap();
}
#[test]
#[should_panic]
fn test_missing_name_and_age() {
let _: Person = ",".try_into().unwrap();
}
#[test]
#[should_panic]
fn test_missing_name_and_invalid_age() {
let _: Person = ",one".try_into().unwrap();
}
}

View file

@ -99,15 +99,12 @@ enum CreationError {
impl fmt::Display for CreationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str((self as &dyn error::Error).description())
let description = match *self {
CreationError::Negative => "Number is negative",
CreationError::Zero => "Number is zero",
};
f.write_str(description)
}
}
impl error::Error for CreationError {
fn description(&self) -> &str {
match *self {
CreationError::Negative => "Negative",
CreationError::Zero => "Zero",
}
}
}
impl error::Error for CreationError {}

View file

@ -1,31 +0,0 @@
// option1.rs
// This example panics because the second time it calls `pop`, the `vec`
// is empty, so `pop` returns `None`, and `unwrap` panics if it's called
// on `None`. Handle this in a more graceful way than calling `unwrap`!
// Execute `rustlings hint option1` for hints :)
// I AM NOT DONE
pub fn pop_too_much() -> bool {
let mut list = vec![3];
let last = list.pop().unwrap();
println!("The last item in the list is {:?}", last);
let second_to_last = list.pop().unwrap();
println!(
"The second-to-last item in the list is {:?}",
second_to_last
);
true
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_not_panic() {
assert!(pop_too_much());
}
}

36
exercises/if/if2.rs Normal file
View file

@ -0,0 +1,36 @@
// if2.rs
// Step 1: Make me compile!
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
// Execute the command `rustlings hint if2` if you want a hint :)
// I AM NOT DONE
pub fn fizz_if_foo(fizzish: &str) -> &str {
if fizzish == "fizz" {
"foo"
} else {
1
}
}
// No test changes needed!
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn foo_for_fizz() {
assert_eq!(fizz_if_foo("fizz"), "foo")
}
#[test]
fn bar_for_fuzz() {
assert_eq!(fizz_if_foo("fuzz"), "bar")
}
#[test]
fn default_to_baz() {
assert_eq!(fizz_if_foo("literally anything"), "baz")
}
}

View file

@ -2,7 +2,7 @@
Rust's macro system is very powerful, but also kind of difficult to wrap your
head around. We're not going to teach you how to write your own fully-featured
modules, instead we'll show you how to use and create them.
macros. Instead, we'll show you how to use and create them.
#### Book Sections

View file

@ -1,8 +1,10 @@
// iterators2.rs
// In this module, you'll learn some of unique advantages that iterators can offer
// Step 1. Complete the `capitalize_first` function to pass the first two cases
// Step 2. Apply the `capitalize_first` function to a vector of strings, ensuring that it returns a vector of strings as well
// Step 3. Apply the `capitalize_first` function again to a list, but try and ensure it returns a single string
// In this module, you'll learn some of unique advantages that iterators can offer.
// Step 1. Complete the `capitalize_first` function to pass the first two cases.
// Step 2. Apply the `capitalize_first` function to a vector of strings.
// Ensure that it returns a vector of strings as well.
// Step 3. Apply the `capitalize_first` function again to a list.
// Try to ensure it returns a single string.
// As always, there are hints if you execute `rustlings hint iterators2`!
// I AM NOT DONE

View file

@ -3,13 +3,13 @@
// I AM NOT DONE
pub fn factorial(num: u64) -> u64 {
// Complete this function to return factorial of num
// Complete this function to return the factorial of num
// Do not use:
// - return
// For extra fun don't use:
// Try not to use:
// - imperative style loops (for, while)
// - additional variables
// For the most fun don't use:
// For an extra challenge, don't use:
// - recursion
// Execute `rustlings hint iterators4` for hints.
}

View file

@ -0,0 +1,67 @@
// structs3.rs
// Structs contain more than simply some data, they can also have logic, in this
// exercise we have defined the Package struct and we want to test some logic attached to it,
// make the code compile and the tests pass! If you have issues execute `rustlings hint structs3`
// I AM NOT DONE
#[derive(Debug)]
struct Package {
from: String,
to: String,
weight: f32
}
impl Package {
fn new(from: String, to: String, weight: f32) -> Package {
if weight <= 0.0 {
// Something goes here...
} else {
return Package {from, to, weight};
}
}
fn is_international(&self) -> ??? {
// Something goes here...
}
fn get_fees(&self, cost_per_kg: f32) -> ??? {
// Something goes here...
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[should_panic]
fn fail_creating_weightless_package() {
let country_from = String::from("Spain");
let country_to = String::from("Austria");
Package::new(country_from, country_to, -2.21);
}
#[test]
fn create_international_package() {
let country_from = String::from("Spain");
let country_to = String::from("Russia");
let package = Package::new(country_from, country_to, 1.2);
assert!(package.is_international());
}
#[test]
fn calculate_transport_fees() {
let country_from = String::from("Spain");
let country_to = String::from("Spain");
let country_fee = ???;
let package = Package::new(country_from, country_to, 22.0);
assert_eq!(package.get_fees(country_fee), 176.0);
}
}

View file

@ -0,0 +1,9 @@
// variables5.rs
// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :)
// I AM NOT DONE
const NUMBER = 3;
fn main() {
println!("Number {}", NUMBER);
}

View file

@ -52,9 +52,25 @@ because we want to assign a different typed value to an existing variable. Somet
you may also like to reuse existing variable names because you are just converting
values to different types like in this exercise.
Fortunately Rust has a powerful solution to this problem: 'Shadowing'!
You can read more about 'Shadowing' in the book's section 'Variables and Mutability'.
You can read more about 'Shadowing' in the book's section 'Variables and Mutability':
https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
Try to solve this exercise afterwards using this technique."""
[[exercises]]
name = "variables6"
path = "exercises/variables/variables6.rs"
mode = "compile"
hint = """
We know about variables and mutability, but there is another important type of
variable available; constants.
Constants are always immutable and they are declared with keyword 'const' rather
then keyword 'let'.
Constants types must also always be annotated.
Read more about constants under 'Differences Between Variables and Constants' in the book's section 'Variables and Mutability':
https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html
"""
# IF
[[exercises]]
@ -71,6 +87,15 @@ Remember in Rust that:
- `if`/`else` conditionals are expressions
- Each condition is followed by a `{}` block."""
[[exercises]]
name = "if2"
path = "exercises/if/if2.rs"
mode = "test"
hint = """
For that first compiler error, it's important in Rust that each conditional
block return the same type! To get the tests passing, you will need a couple
conditions checking different input values."""
# FUNCTIONS
[[exercises]]
@ -199,13 +224,35 @@ Now you have another tool in your toolbox!"""
name = "structs1"
path = "exercises/structs/structs1.rs"
mode = "test"
hint = "No hints this time ;)"
hint = """
Rust has more than one type of struct. Both variants are used to package related data together.
On the one hand, there are normal, or classic, structs. These are named collections of related data stored in fields.
The other variant is tuple structs. Basically just named tuples.
In this exercise you need to implement one of each kind.
Read more about structs in The Book: https://doc.rust-lang.org/stable/book/ch05-00-structs.html"""
[[exercises]]
name = "structs2"
path = "exercises/structs/structs2.rs"
mode = "test"
hint = "No hints this time ;)"
hint = """
Creating instances of structs is easy, all you need to do is assign some values to its fields.
There is however some shortcuts that can be taken when instantiating structs.
Have a look in The Book, to find out more: https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax"""
[[exercises]]
name = "structs3"
path = "exercises/structs/structs3.rs"
mode = "test"
hint = """
The new method needs to panic if the weight is physically impossible :), how do we do that in Rust?
For is_international: What makes a package international? Seems related to the places it goes through right?
For calculate_transport_fees: Bigger is more expensive usually, we don't have size, but something may fit the bill here :)
Have a look in The Book, to find out more about method implementations: https://doc.rust-lang.org/book/ch05-03-method-syntax.html"""
# STRINGS
@ -476,7 +523,7 @@ mode = "test"
hint = """
First hint: To figure out what type should go where the ??? is, take a look
at the test helper function `test_with_str`, since it returns whatever
`read_and_validate` returns and`test_with_str` has its signature fully
`read_and_validate` returns and `test_with_str` has its signature fully
specified.
@ -615,10 +662,10 @@ name = "iterators4"
path = "exercises/standard_library_types/iterators4.rs"
mode = "test"
hint = """
In an imperative language you might write a for loop to iterate through
multiply the values into a mutable variable. Or you might write code more
functionally with recursion and a match clause. But you can also use ranges
and iterators to solve this in rust."""
In an imperative language, you might write a for loop that updates
a mutable variable. Or, you might write code utilizing recursion
and a match clause. In Rust you can take another functional
approach, computing the factorial elegantly with ranges and iterators."""
# TRAITS

View file

@ -30,6 +30,22 @@ else
exit 1
fi
# Look up python installations, starting with 3 with a fallback of 2
if [ -x "$(command -v python3)" ]
then
PY="$(command -v python3)"
elif [ -x "$(command -v python)" ]
then
PY="$(command -v python)"
elif [ -x "$(command -v python2)" ]
then
PY="$(command -v python2)"
else
echo "ERROR: No working python installation was found"
echo "Please install python and add it to the PATH variable"
exit 1
fi
# Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0).
# Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2.
function vercomp() {
@ -86,7 +102,7 @@ Path=${1:-rustlings/}
echo "Cloning Rustlings at $Path..."
git clone -q https://github.com/rust-lang/rustlings $Path
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
echo "Checking out version $Version..."