mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-26 00:11:49 +02:00
Compare commits
296 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a303d508cf | ||
|
|
44d39112ff | ||
|
|
28020d0c54 | ||
|
|
0ef95947cc | ||
|
|
4ac70a99ae | ||
|
|
bcf14cf677 | ||
|
|
1dae782cd4 | ||
|
|
90cfb6ff28 | ||
|
|
26110da7ca | ||
|
|
30644c9a06 | ||
|
|
033bf1198f | ||
|
|
cdc7d92e57 | ||
|
|
af0e3b8f17 | ||
|
|
04f1d079aa | ||
|
|
9b6c629397 | ||
|
|
5aa467bef2 | ||
|
|
af7ad27f89 | ||
|
|
d6d57bfbb8 | ||
|
|
4f4cfcf3c3 | ||
|
|
fa9f522b7f | ||
|
|
838f9f3008 | ||
|
|
96347df9df | ||
|
|
9334783da3 | ||
|
|
964b2a331d | ||
|
|
95ccd92616 | ||
|
|
197d3a3d89 | ||
|
|
a7ddd747ca | ||
|
|
d61b4e5a13 | ||
|
|
68e646f8aa | ||
|
|
21bfb2d477 | ||
|
|
a9dae71188 | ||
|
|
dd84cc5fd4 | ||
|
|
51631f4c2e | ||
|
|
535a8c8243 | ||
|
|
7abfbd23d0 | ||
|
|
633c00cf80 | ||
|
|
0c12fa31c5 | ||
|
|
5643ef05bc | ||
|
|
f38f42f17d | ||
|
|
472d8592d6 | ||
|
|
4fb230daf1 | ||
|
|
e6bde22f9c | ||
|
|
cc5b9b772a | ||
|
|
ded1474bbb | ||
|
|
2b1fb2b739 | ||
|
|
18e0bfef1d | ||
|
|
3be760dc38 | ||
|
|
29dd0b1e41 | ||
|
|
e1fdfbb062 | ||
|
|
89c07b5e43 | ||
|
|
9b5350eab1 | ||
|
|
5382cd696a | ||
|
|
69fc9ce10e | ||
|
|
13ac6f38dc | ||
|
|
2ec0bdfd99 | ||
|
|
c03e1e6c6c | ||
|
|
2a682abeef | ||
|
|
9f38b54a2d | ||
|
|
2933f51949 | ||
|
|
a75300b8c7 | ||
|
|
01f4bb86c3 | ||
|
|
79c3ada49b | ||
|
|
ac276d06fa | ||
|
|
c7eabe61bb | ||
|
|
8f28bcf704 | ||
|
|
be3b289a10 | ||
|
|
19a0c1f3cb | ||
|
|
dc94fcc6e8 | ||
|
|
183237c858 | ||
|
|
599a44f90f | ||
|
|
08e9c7aa2f | ||
|
|
a893d04e81 | ||
|
|
5996bd57ea | ||
|
|
909b297ae3 | ||
|
|
abdc3b2211 | ||
|
|
e66d2085b7 | ||
|
|
4a5e48e88f | ||
|
|
3a586a0c19 | ||
|
|
144dec3fd3 | ||
|
|
448d116a89 | ||
|
|
8493e5d09f | ||
|
|
83e7365fd8 | ||
|
|
b6040e6061 | ||
|
|
858b9a5119 | ||
|
|
00fbcd14f7 | ||
|
|
062f18d353 | ||
|
|
58760bce54 | ||
|
|
ca4f026074 | ||
|
|
f285ac2281 | ||
|
|
0f3db4dbb9 | ||
|
|
18b2d451cd | ||
|
|
b6dd1af7d2 | ||
|
|
303c8ee7cd | ||
|
|
98d6b15fc0 | ||
|
|
77f407dd5f | ||
|
|
a12a3ef08b | ||
|
|
6480fcaf7c | ||
|
|
f5cb439fe6 | ||
|
|
15c9e85690 | ||
|
|
8f8a85303b | ||
|
|
114cc2db21 | ||
|
|
bec97b6c76 | ||
|
|
114b54cbdb | ||
|
|
0f16463794 | ||
|
|
8ff5fde88e | ||
|
|
3286c5ec19 | ||
|
|
ee7cdc66b3 | ||
|
|
9699da4968 | ||
|
|
6bb0b48b10 | ||
|
|
70da09eae2 | ||
|
|
101072ab9f | ||
|
|
47f7672c03 | ||
|
|
dd54ccf677 | ||
|
|
66ec916b3d | ||
|
|
b4062ef699 | ||
|
|
2d3816341e | ||
|
|
d1054cd596 | ||
|
|
81f8c2f83c | ||
|
|
3144d3ae63 | ||
|
|
9642f5a3f6 | ||
|
|
c4853ee6bb | ||
|
|
1cc40bc9ce | ||
|
|
38a615f407 | ||
|
|
4f2468e14f | ||
|
|
8f7b5bd00e | ||
|
|
4821a8be94 | ||
|
|
523d18b873 | ||
|
|
c52be7dfcb | ||
|
|
c2bfcf1c54 | ||
|
|
bb5f404e35 | ||
|
|
106dbbc341 | ||
|
|
4b6540c71a | ||
|
|
816b1f5e85 | ||
|
|
9f61db5dbe | ||
|
|
e823bef970 | ||
|
|
f9ccc6a289 | ||
|
|
b32a666541 | ||
|
|
b636825de3 | ||
|
|
ddd98ad75d | ||
|
|
d355927024 | ||
|
|
75c0053bb1 | ||
|
|
55a9284665 | ||
|
|
113cdae2d4 | ||
|
|
c6295ade33 | ||
|
|
e1e453075f | ||
|
|
9ca08b8f2b | ||
|
|
f47d3f422d | ||
|
|
e6bd8021d9 | ||
|
|
307252e9ae | ||
|
|
bb2ca25110 | ||
|
|
9e4fb1009f | ||
|
|
8ad5f9bf53 | ||
|
|
02a2fe4871 | ||
|
|
40741c5b0b | ||
|
|
0dd1c6ca6b | ||
|
|
5563adbb89 | ||
|
|
524e17df10 | ||
|
|
73e848e96f | ||
|
|
5f0806967c | ||
|
|
173bb14140 | ||
|
|
918f310674 | ||
|
|
a75fdbd8ad | ||
|
|
9d3f189b0e | ||
|
|
7e79c51222 | ||
|
|
a180d831a1 | ||
|
|
e81adc2752 | ||
|
|
500422d594 | ||
|
|
0311c03735 | ||
|
|
df81141d6f | ||
|
|
cce6a44277 | ||
|
|
7479a4737b | ||
|
|
06ef4cc654 | ||
|
|
c7c3130507 | ||
|
|
010a045692 | ||
|
|
51666609f1 | ||
|
|
10967bce57 | ||
|
|
763aa6e378 | ||
|
|
d6c0a688e6 | ||
|
|
9f75554f2a | ||
|
|
2b20c8a0f5 | ||
|
|
1b4590b42b | ||
|
|
09e89bbcd3 | ||
|
|
7c4b1f910c | ||
|
|
3ceabe91f8 | ||
|
|
a39ffb2fb8 | ||
|
|
41f989135d | ||
|
|
f6cffc7e48 | ||
|
|
1da84b5f7c | ||
|
|
ebfe76cdb6 | ||
|
|
c301814d68 | ||
|
|
09478571df | ||
|
|
a901499ede | ||
|
|
de65026db0 | ||
|
|
071b51d588 | ||
|
|
80390d8a03 | ||
|
|
9590082848 | ||
|
|
9cfb617d5b | ||
|
|
b66e2e0962 | ||
|
|
32721bbc83 | ||
|
|
19fb1c240c | ||
|
|
630ff0e00b | ||
|
|
964c974a02 | ||
|
|
c9e4f2cfb4 | ||
|
|
a3a554aeed | ||
|
|
6c3cc2caf5 | ||
|
|
5999acd24a | ||
|
|
59f56b24d9 | ||
|
|
abd0ec379c | ||
|
|
cfb98a5617 | ||
|
|
fafcffed25 | ||
|
|
3f1209ce19 | ||
|
|
b217961254 | ||
|
|
cd06b39a42 | ||
|
|
84e1f85be2 | ||
|
|
f060f099d4 | ||
|
|
e093af4c05 | ||
|
|
eface5ef45 | ||
|
|
5b72f478a7 | ||
|
|
5f5a0465cb | ||
|
|
f509e479a1 | ||
|
|
ad00c2cf51 | ||
|
|
a20f80623e | ||
|
|
f26dca6d8e | ||
|
|
9ea089a5d9 | ||
|
|
f07d1c9488 | ||
|
|
0d0c79a5cb | ||
|
|
9bb5aa583f | ||
|
|
f26ed591f3 | ||
|
|
0b4576a028 | ||
|
|
d7bb220ba3 | ||
|
|
f907c710b2 | ||
|
|
c6bcb319f8 | ||
|
|
443600194c | ||
|
|
7b6f14c25a | ||
|
|
887d919323 | ||
|
|
74d32f0cca | ||
|
|
3f479be7e7 | ||
|
|
95d02a23d0 | ||
|
|
8b59b9852f | ||
|
|
53bda94f77 | ||
|
|
52580cfd0d | ||
|
|
cf3d5b44e6 | ||
|
|
491dc2e5ca | ||
|
|
b89cdef120 | ||
|
|
348fe339b9 | ||
|
|
e79d7ea981 | ||
|
|
e7841ba2ed | ||
|
|
37687e9323 | ||
|
|
b749314944 | ||
|
|
3eb0fb5aa6 | ||
|
|
44a4cf3b27 | ||
|
|
9a8762ba6e | ||
|
|
2e1bd5ef4e | ||
|
|
a9dc101701 | ||
|
|
e2835de137 | ||
|
|
535e7a6a28 | ||
|
|
fe96de2e2d | ||
|
|
9fd881443f | ||
|
|
2ff3f7ae13 | ||
|
|
2b80f6ed41 | ||
|
|
3ab084a421 | ||
|
|
495174ff7c | ||
|
|
b049fa2c84 | ||
|
|
052f0aa7d4 | ||
|
|
60393999b8 | ||
|
|
b3a3351e8e | ||
|
|
86b5c08b9b | ||
|
|
dab90f7b91 | ||
|
|
71d31256a6 | ||
|
|
3b6d5c3aaa | ||
|
|
7ce42941ea | ||
|
|
3f8171475c | ||
|
|
b135b589e0 | ||
|
|
05ca3d77f7 | ||
|
|
6deee7e3e9 | ||
|
|
9dc404077a | ||
|
|
30e6af6069 | ||
|
|
9788496a85 | ||
|
|
6d3a412d47 | ||
|
|
700b236f4d | ||
|
|
bc22ec382f | ||
|
|
135e5d47a7 | ||
|
|
0f8001ea44 | ||
|
|
5b6e23c323 | ||
|
|
29b30ec946 | ||
|
|
76be5e4e99 | ||
|
|
8b9479071c | ||
|
|
3d9b03c52b | ||
|
|
a03d9655a8 | ||
|
|
1e2fd9c92f | ||
|
|
7e8530b21f | ||
|
|
98358597a9 | ||
|
|
8064facbb8 | ||
|
|
f981dcfde4 | ||
|
|
bbf8922ef7 | ||
|
|
43dc31193a |
666
.all-contributorsrc
Normal file
666
.all-contributorsrc
Normal file
@@ -0,0 +1,666 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "uce",
|
||||
"name": "Ufuk Celebi",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/1756620?v=4",
|
||||
"profile": "https://github.com/uce",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "lebedevsergey",
|
||||
"name": "lebedevsergey",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/7325764?v=4",
|
||||
"profile": "https://github.com/lebedevsergey",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "avrong",
|
||||
"name": "Aleksei Trifonov",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/6342851?v=4",
|
||||
"profile": "https://github.com/avrong",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Darrenmeehan",
|
||||
"name": "Darren Meehan",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/411136?v=4",
|
||||
"profile": "https://drn.ie",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "jihchi",
|
||||
"name": "Jihchi Lee",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/87983?v=4",
|
||||
"profile": "https://github.com/jihchi",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "bertonha",
|
||||
"name": "Christofer Bertonha",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/1225902?v=4",
|
||||
"profile": "https://github.com/bertonha",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "apatniv",
|
||||
"name": "Vivek Bharath Akupatni",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/22565917?v=4",
|
||||
"profile": "https://github.com/apatniv",
|
||||
"contributions": [
|
||||
"code",
|
||||
"test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "DiD92",
|
||||
"name": "Dídac Sementé Fernández",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/6002416?v=4",
|
||||
"profile": "https://github.com/DiD92",
|
||||
"contributions": [
|
||||
"code",
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "wrobstory",
|
||||
"name": "Rob Story",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/2601457?v=4",
|
||||
"profile": "https://github.com/wrobstory",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "siobhanjacobson",
|
||||
"name": "Siobhan Jacobson",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/28983835?v=4",
|
||||
"profile": "https://github.com/siobhanjacobson",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "EvanCarroll",
|
||||
"name": "Evan Carroll",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/19922?v=4",
|
||||
"profile": "https://www.linkedin.com/in/evancarroll/",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "jmahmood",
|
||||
"name": "Jawaad Mahmood",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/95606?v=4",
|
||||
"profile": "http://www.jawaadmahmood.com",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "GaurangTandon",
|
||||
"name": "Gaurang Tandon",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/6308683?v=4",
|
||||
"profile": "https://github.com/GaurangTandon",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "dev-cyprium",
|
||||
"name": "Stefan Kupresak",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/6002628?v=4",
|
||||
"profile": "https://github.com/dev-cyprium",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "greg-el",
|
||||
"name": "Greg Leonard",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/45019882?v=4",
|
||||
"profile": "https://github.com/greg-el",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "ryanpcmcquen",
|
||||
"name": "Ryan McQuen",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/772937?v=4",
|
||||
"profile": "https://ryanpcmcquen.org",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "AnnikaCodes",
|
||||
"name": "Annika",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/56906084?v=4",
|
||||
"profile": "https://github.com/AnnikaCodes",
|
||||
"contributions": [
|
||||
"review"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "darnuria",
|
||||
"name": "Axel Viala",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/2827553?v=4",
|
||||
"profile": "https://darnuria.eu",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "sazid",
|
||||
"name": "Mohammed Sazid Al Rashid",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/2370167?v=4",
|
||||
"profile": "https://sazid.github.io",
|
||||
"contributions": [
|
||||
"content",
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "seeplusplus",
|
||||
"name": "Caleb Webber",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/17479099?v=4",
|
||||
"profile": "https://codingthemsoftly.com",
|
||||
"contributions": [
|
||||
"maintenance"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "pcn",
|
||||
"name": "Peter N",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/1056756?v=4",
|
||||
"profile": "https://github.com/pcn",
|
||||
"contributions": [
|
||||
"maintenance"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "seancad",
|
||||
"name": "seancad",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/47405611?v=4",
|
||||
"profile": "https://github.com/seancad",
|
||||
"contributions": [
|
||||
"maintenance"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 8,
|
||||
"projectName": "rustlings",
|
||||
"projectOwner": "rust-lang",
|
||||
"repoType": "github",
|
||||
"repoHost": "https://github.com",
|
||||
"skipCi": true
|
||||
}
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -2,3 +2,8 @@
|
||||
target/
|
||||
**/*.rs.bk
|
||||
.DS_Store
|
||||
*.pdb
|
||||
exercises/clippy/Cargo.toml
|
||||
exercises/clippy/Cargo.lock
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
7
.gitpod.yml
Normal file
7
.gitpod.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
tasks:
|
||||
- init: /workspace/rustlings/install.sh
|
||||
command: /workspace/.cargo/bin/rustlings watch
|
||||
|
||||
vscode:
|
||||
extensions:
|
||||
- rust-lang.rust@0.7.8:CvNqMTgDdt3UXt+6BCDTVg==
|
||||
2
.replit
Normal file
2
.replit
Normal file
@@ -0,0 +1,2 @@
|
||||
language = "rust"
|
||||
run = "[ -x ~/.cargo/bin/rustlings ] && ~/.cargo/bin/rustlings watch || ./install.sh"
|
||||
11
.travis.yml
11
.travis.yml
@@ -1,11 +0,0 @@
|
||||
language: rust
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
script: cargo test --verbose
|
||||
matrix:
|
||||
allow_failures:
|
||||
- rust: nightly
|
||||
fast_finish: true
|
||||
cache: cargo
|
||||
147
CHANGELOG.md
147
CHANGELOG.md
@@ -1,3 +1,146 @@
|
||||
<a name="4.3.0"></a>
|
||||
## 4.3.0 (2020-12-29)
|
||||
|
||||
#### Features
|
||||
|
||||
* Rewrite default out text ([44d39112](https://github.com/rust-lang/rustlings/commit/44d39112ff122b29c9793fe52e605df1612c6490))
|
||||
* match exercise order to book chapters (#541) ([033bf119](https://github.com/rust-lang/rustlings/commit/033bf1198fc8bfce1b570e49da7cde010aa552e3))
|
||||
* Crab? (#586) ([fa9f522b](https://github.com/rust-lang/rustlings/commit/fa9f522b7f043d7ef73a39f003a9272dfe72c4f4))
|
||||
* add "rustlings list" command ([838f9f30](https://github.com/rust-lang/rustlings/commit/838f9f30083d0b23fd67503dcf0fbeca498e6647))
|
||||
* **try_from_into:** remove duplicate annotation ([04f1d079](https://github.com/rust-lang/rustlings/commit/04f1d079aa42a2f49af694bc92c67d731d31a53f))
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* update structs README ([bcf14cf6](https://github.com/rust-lang/rustlings/commit/bcf14cf677adb3a38a3ac3ca53f3c69f61153025))
|
||||
* added missing exercises to info.toml ([90cfb6ff](https://github.com/rust-lang/rustlings/commit/90cfb6ff28377531bfc34acb70547bdb13374f6b))
|
||||
* gives a bit more context to magic number ([30644c9a](https://github.com/rust-lang/rustlings/commit/30644c9a062b825c0ea89435dc59f0cad86b110e))
|
||||
* **functions2:** Change signature to trigger precise error message: (#605) ([0ef95947](https://github.com/rust-lang/rustlings/commit/0ef95947cc30482e63a7045be6cc2fb6f6dcb4cc))
|
||||
* **structs1:** Adjust wording (#573) ([9334783d](https://github.com/rust-lang/rustlings/commit/9334783da31d821cc59174fbe8320df95828926c))
|
||||
* **try_from_into:**
|
||||
* type error ([4f4cfcf3](https://github.com/rust-lang/rustlings/commit/4f4cfcf3c36c8718c7c170c9c3a6935e6ef0618c))
|
||||
* Update description (#584) ([96347df9](https://github.com/rust-lang/rustlings/commit/96347df9df294f01153b29d9ad4ba361f665c755))
|
||||
* **vec1:** Have test compare every element in a and v ([9b6c6293](https://github.com/rust-lang/rustlings/commit/9b6c629397b24b944f484f5b2bbd8144266b5695))
|
||||
|
||||
<a name="4.2.0"></a>
|
||||
## 4.2.0 (2020-11-07)
|
||||
|
||||
#### Features
|
||||
|
||||
* Add HashMap exercises ([633c00cf](https://github.com/rust-lang/rustlings/commit/633c00cf8071e1e82959a3010452a32f34f29fc9))
|
||||
* Add Vec exercises ([0c12fa31](https://github.com/rust-lang/rustlings/commit/0c12fa31c57c03c6287458a0a8aca7afd057baf6))
|
||||
* **primitive_types6:** Add a test (#548) ([2b1fb2b7](https://github.com/rust-lang/rustlings/commit/2b1fb2b739bf9ad8d6b7b12af25fee173011bfc4))
|
||||
* **try_from_into:** Add tests (#571) ([95ccd926](https://github.com/rust-lang/rustlings/commit/95ccd92616ae79ba287cce221101e0bbe4f68cdc))
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* log error output when inotify limit is exceeded ([d61b4e5a](https://github.com/rust-lang/rustlings/commit/d61b4e5a13b44d72d004082f523fa1b6b24c1aca))
|
||||
* more unique temp_file ([5643ef05](https://github.com/rust-lang/rustlings/commit/5643ef05bc81e4a840e9456f4406a769abbe1392))
|
||||
* **installation:** Update the MinRustVersion ([21bfb2d4](https://github.com/rust-lang/rustlings/commit/21bfb2d4777429c87d8d3b5fbf0ce66006dcd034))
|
||||
* **iterators2:** Update description (#578) ([197d3a3d](https://github.com/rust-lang/rustlings/commit/197d3a3d8961b2465579218a6749b2b2cefa8ddd))
|
||||
* **primitive_types6:**
|
||||
* remove 'unused doc comment' warning ([472d8592](https://github.com/rust-lang/rustlings/commit/472d8592d65c8275332a20dfc269e7ac0d41bc88))
|
||||
* missing comma in test ([4fb230da](https://github.com/rust-lang/rustlings/commit/4fb230daf1251444fcf29e085cee222a91f8a37e))
|
||||
* **quiz3:** Second test is for odd numbers, not even. (#553) ([18e0bfef](https://github.com/rust-lang/rustlings/commit/18e0bfef1de53071e353ba1ec5837002ff7290e6))
|
||||
|
||||
<a name="4.1.0"></a>
|
||||
## 4.1.0 (2020-10-05)
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* Update rustlings version in Cargo.lock ([1cc40bc9](https://github.com/rust-lang/rustlings/commit/1cc40bc9ce95c23d56f6d91fa1c4deb646231fef))
|
||||
* **arc1:** index mod should equal thread count ([b4062ef6](https://github.com/rust-lang/rustlings/commit/b4062ef6993e80dac107c4093ea85166ad3ee0fa))
|
||||
* **enums3:** Update Message::ChangeColor to take a tuple. (#457) ([4b6540c7](https://github.com/rust-lang/rustlings/commit/4b6540c71adabad647de8a09e57295e7c7c7d794))
|
||||
* **exercises:** adding question mark to quiz2 ([101072ab](https://github.com/rust-lang/rustlings/commit/101072ab9f8c80b40b8b88cb06cbe38aca2481c5))
|
||||
* **generics3:** clarify grade change ([47f7672c](https://github.com/rust-lang/rustlings/commit/47f7672c0307732056e7426e81d351f0dd7e22e5))
|
||||
* **structs3:** Small adjustment of variable name ([114b54cb](https://github.com/rust-lang/rustlings/commit/114b54cbdb977234b39e5f180d937c14c78bb8b2))
|
||||
* **using_as:** Add test so that proper type is returned. (#512) ([3286c5ec](https://github.com/rust-lang/rustlings/commit/3286c5ec19ea5fb7ded81d047da5f8594108a490))
|
||||
|
||||
#### Features
|
||||
|
||||
* Added iterators1.rs exercise ([9642f5a3](https://github.com/rust-lang/rustlings/commit/9642f5a3f686270a4f8f6ba969919ddbbc4f7fdd))
|
||||
* Add ability to run rustlings on repl.it (#471) ([8f7b5bd0](https://github.com/rust-lang/rustlings/commit/8f7b5bd00eb83542b959830ef55192d2d76db90a))
|
||||
* Add gitpod support (#473) ([4821a8be](https://github.com/rust-lang/rustlings/commit/4821a8be94af4f669042a06ab917934cfacd032f))
|
||||
* Remind the user of the hint option (#425) ([816b1f5e](https://github.com/rust-lang/rustlings/commit/816b1f5e85d6cc6e72673813a85d0ada2a8f84af))
|
||||
* Remind the user of the hint option (#425) ([9f61db5d](https://github.com/rust-lang/rustlings/commit/9f61db5dbe38538cf06571fcdd5f806e7901e83a))
|
||||
* **cli:** Added 'cls' command to 'watch' mode (#474) ([4f2468e1](https://github.com/rust-lang/rustlings/commit/4f2468e14f574a93a2e9b688367b5752ed96ae7b))
|
||||
* **try_from_into:** Add insufficient length test (#469) ([523d18b8](https://github.com/rust-lang/rustlings/commit/523d18b873a319f7c09262f44bd40e2fab1830e5))
|
||||
|
||||
<a name="4.0.0"></a>
|
||||
## 4.0.0 (2020-07-08)
|
||||
|
||||
#### Breaking Changes
|
||||
|
||||
* Add a --nocapture option to display test harnesses' outputs ([8ad5f9bf](https://github.com/rust-lang/rustlings/commit/8ad5f9bf531a4848b1104b7b389a20171624c82f))
|
||||
* Rename test to quiz, fixes #244 ([010a0456](https://github.com/rust-lang/rustlings/commit/010a04569282149cea7f7a76fc4d7f4c9f0f08dd))
|
||||
|
||||
#### Features
|
||||
|
||||
* Add traits README ([173bb141](https://github.com/rust-lang/rustlings/commit/173bb14140c5530cbdb59e53ace3991a99d804af))
|
||||
* Add box1.rs exercise ([7479a473](https://github.com/rust-lang/rustlings/commit/7479a4737bdcac347322ad0883ca528c8675e720))
|
||||
* Rewrite try_from_into (#393) ([763aa6e3](https://github.com/rust-lang/rustlings/commit/763aa6e378a586caae2d8d63755a85eeba227933))
|
||||
* Add if2 exercise ([1da84b5f](https://github.com/rust-lang/rustlings/commit/1da84b5f7c489f65bd683c244f13c7d1ee812df0))
|
||||
* Added exercise structs3.rs ([b66e2e09](https://github.com/rust-lang/rustlings/commit/b66e2e09622243e086a0f1258dd27e1a2d61c891))
|
||||
* Add exercise variables6 covering const (#352) ([5999acd2](https://github.com/rust-lang/rustlings/commit/5999acd24a4f203292be36e0fd18d385887ec481))
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* Change then to than ([ddd98ad7](https://github.com/rust-lang/rustlings/commit/ddd98ad75d3668fbb10eff74374148aa5ed2344d))
|
||||
* rename quiz1 to tests1 in info (#420) ([0dd1c6ca](https://github.com/rust-lang/rustlings/commit/0dd1c6ca6b389789e0972aa955fe17aa15c95f29))
|
||||
* fix quiz naming inconsistency (#421) ([5563adbb](https://github.com/rust-lang/rustlings/commit/5563adbb890587fc48fbbc9c4028642687f1e85b))
|
||||
* confine the user further in variable exercises ([06ef4cc6](https://github.com/rust-lang/rustlings/commit/06ef4cc654e75d22a526812919ee49b8956280bf))
|
||||
* update iterator and macro text for typos and clarity ([95900828](https://github.com/rust-lang/rustlings/commit/959008284834bece0196a01e17ac69a7e3590116))
|
||||
* update generics2 closes #362 ([964c974a](https://github.com/rust-lang/rustlings/commit/964c974a0274199d755073b917c2bc5da0c9b4f1))
|
||||
* confusing comment in conversions/try_from_into.rs ([c9e4f2cf](https://github.com/rust-lang/rustlings/commit/c9e4f2cfb4c48d0b7451263cfb43b9426438122d))
|
||||
* **arc1:** Passively introduce attributes (#429) ([113cdae2](https://github.com/rust-lang/rustlings/commit/113cdae2d4e4c55905e8056ad326ede7fd7de356))
|
||||
* **box1:** fix comment typo (#426) ([bb2ca251](https://github.com/rust-lang/rustlings/commit/bb2ca251106b27a7272d9a30872904dd1376654c))
|
||||
* **errorsn:** Try harder to confine the user. (#388) ([2b20c8a0](https://github.com/rust-lang/rustlings/commit/2b20c8a0f5774d07c58d110d75879f33fc6273b5))
|
||||
* **from_into.rs:** typo ([a901499e](https://github.com/rust-lang/rustlings/commit/a901499ededd3ce1995164700514fe4e9a0373ea))
|
||||
* **generics2:** Guide students to the answer (#430) ([e6bd8021](https://github.com/rust-lang/rustlings/commit/e6bd8021d9a7dd06feebc30c9d5f953901d7b419))
|
||||
* **installation:**
|
||||
* Provide a backup git reference when tag can't be curl ([9e4fb100](https://github.com/rust-lang/rustlings/commit/9e4fb1009f1c9e3433915c03e22c2af422e5c5fe))
|
||||
* Check if python is available while checking for git,rustc and cargo ([9cfb617d](https://github.com/rust-lang/rustlings/commit/9cfb617d5b0451b4b51644a1298965390cda9884))
|
||||
* **option1:**
|
||||
* Don't add only zeros to the numbers array ([cce6a442](https://github.com/rust-lang/rustlings/commit/cce6a4427718724a9096800754cd3abeca6a1580))
|
||||
* Add cast to usize, as it is confusing in the context of an exercise about Option ([f6cffc7e](https://github.com/rust-lang/rustlings/commit/f6cffc7e487b42f15a6f958e49704c93a8d4465b))
|
||||
* **option2:** Add TODO to comments (#400) ([10967bce](https://github.com/rust-lang/rustlings/commit/10967bce57682812dc0891a9f9757da1a9d87404))
|
||||
* **options1:** Add hint about Array Initialization (#389) ([9f75554f](https://github.com/rust-lang/rustlings/commit/9f75554f2a30295996f03f0160b98c0458305502))
|
||||
* **test2:** name of type String and &str (#394) ([d6c0a688](https://github.com/rust-lang/rustlings/commit/d6c0a688e6a96f93ad60d540d4b326f342fc0d45))
|
||||
* **variables6:** minor typo (#419) ([524e17df](https://github.com/rust-lang/rustlings/commit/524e17df10db95f7b90a0f75cc8997182a8a4094))
|
||||
|
||||
<a name="3.0.0"></a>
|
||||
## 3.0.0 (2020-04-11)
|
||||
|
||||
#### Breaking Changes
|
||||
|
||||
* make "compile" exercises print output (#278) ([3b6d5c](https://github.com/fmoko/rustlings/commit/3b6d5c3aaa27a242a832799eb66e96897d26fde3))
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* **primitive_types:** revert primitive_types4 (#296) ([b3a3351e](https://github.com/rust-lang/rustlings/commit/b3a3351e8e6a0bdee07077d7b0382953821649ae))
|
||||
* **run:** compile clippy exercise files (#295) ([3ab084a4](https://github.com/rust-lang/rustlings/commit/3ab084a421c0f140ae83bf1fc3f47b39342e7373))
|
||||
* **conversions:**
|
||||
* add additional test to meet exercise rules (#284) ([bc22ec3](https://github.com/fmoko/rustlings/commit/bc22ec382f843347333ef1301fc1bad773657f38))
|
||||
* remove duplicate not done comment (#292) ([dab90f](https://github.com/fmoko/rustlings/commit/dab90f7b91a6000fe874e3d664f244048e5fa342))
|
||||
* don't hardcode documentation version for traits (#288) ([30e6af](https://github.com/fmoko/rustlings/commit/30e6af60690c326fb5d3a9b7335f35c69c09137d))
|
||||
|
||||
#### Features
|
||||
|
||||
* add Option2 exercise (#290) ([86b5c08b](https://github.com/rust-lang/rustlings/commit/86b5c08b9bea1576127a7c5f599f5752072c087d))
|
||||
* add excercise for option (#282) ([135e5d47](https://github.com/rust-lang/rustlings/commit/135e5d47a7c395aece6f6022117fb20c82f2d3d4))
|
||||
* add new exercises for generics (#280) ([76be5e4e](https://github.com/rust-lang/rustlings/commit/76be5e4e991160f5fd9093f03ee2ba260e8f7229))
|
||||
* **ci:** add buildkite config ([b049fa2c](https://github.com/rust-lang/rustlings/commit/b049fa2c84dba0f0c8906ac44e28fd45fba51a71))
|
||||
|
||||
<a name="2.2.1"></a>
|
||||
### 2.2.1 (2020-02-27)
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* Re-add cloning the repo to install scripts ([3d9b03c5](https://github.com/rust-lang/rustlings/commit/3d9b03c52b8dc51b140757f6fd25ad87b5782ef5))
|
||||
|
||||
#### Features
|
||||
|
||||
* Add clippy lints (#269) ([1e2fd9c9](https://github.com/rust-lang/rustlings/commit/1e2fd9c92f8cd6e389525ca1a999fca4c90b5921))
|
||||
|
||||
<a name="2.2.0"></a>
|
||||
## 2.2.0 (2020-02-25)
|
||||
|
||||
@@ -7,14 +150,14 @@
|
||||
* Update deps to version compatable with aarch64-pc-windows (#263) ([19a93428](https://github.com/rust-lang/rustlings/commit/19a93428b3c73d994292671f829bdc8e5b7b3401))
|
||||
* **docs:**
|
||||
* Added a necessary step to Windows installation process (#242) ([3906efcd](https://github.com/rust-lang/rustlings/commit/3906efcd52a004047b460ed548037093de3f523f))
|
||||
* Fixed mangled sentence from book; edited for clarity (#266) ([ade52ff](https://github.com/rust-lang/rustlings/commit/ade52ffb739987287ddd5705944c8777705faed9))
|
||||
* Fixed mangled sentence from book; edited for clarity (#266) ([ade52ff](https://github.com/rust-lang/rustlings/commit/ade52ffb739987287ddd5705944c8777705faed9))
|
||||
* Updated iterators readme to account for iterators4 exercise (#273) ([bec8e3a](https://github.com/rust-lang/rustlings/commit/bec8e3a644cbd88db1c73ea5f1d8a364f4a34016))
|
||||
* **installation:** make fatal errors more obvious (#272) ([17d0951e](https://github.com/rust-lang/rustlings/commit/17d0951e66fda8e11b204d5c4c41a0d5e22e78f7))
|
||||
* **iterators2:**
|
||||
* Remove reference to missing iterators2.rs (#245) ([419f7797](https://github.com/rust-lang/rustlings/commit/419f7797f294e4ce6a2b883199731b5bde77d262))
|
||||
* **as_ref_mut:** Enable a test and improve per clippy's suggestion (#256) ([dfdf809](https://github.com/rust-lang/rustlings/commit/dfdf8093ebbd4145864995627b812780de52f902))
|
||||
* **tests1:**
|
||||
* Change test command ([fe10e06c](https://github.com/rust-lang/rustlings/commit/fe10e06c3733ddb4a21e90d09bf79bfe618e97ce)
|
||||
* Change test command ([fe10e06c](https://github.com/rust-lang/rustlings/commit/fe10e06c3733ddb4a21e90d09bf79bfe618e97ce)
|
||||
* Correct test command in tests1.rs comment (#263) ([39fa7ae](https://github.com/rust-lang/rustlings/commit/39fa7ae8b70ad468da49b06f11b2383135a63bcf))
|
||||
|
||||
#### Features
|
||||
|
||||
590
Cargo.lock
generated
590
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "rustlings"
|
||||
version = "2.2.0"
|
||||
authors = ["Marisa <mokou@posteo.de>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com"]
|
||||
version = "4.3.0"
|
||||
authors = ["Marisa <mokou@posteo.de>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
155
README.md
155
README.md
@@ -1,4 +1,7 @@
|
||||

|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
# rustlings 🦀❤️
|
||||
|
||||
@@ -6,7 +9,7 @@ Greetings and welcome to `rustlings`. This project contains small exercises to g
|
||||
|
||||
_...looking for the old, web-based version of Rustlings? Try [here](https://github.com/rust-lang/rustlings/tree/rustlings-1)_
|
||||
|
||||
Alternatively, for a first-time Rust learner, there's several other resources:
|
||||
Alternatively, for a first-time Rust learner, there are several other resources:
|
||||
|
||||
- [The Book](https://doc.rust-lang.org/book/index.html) - The most comprehensive resource for learning Rust, but a bit theoretical sometimes. You will be using this along with Rustlings!
|
||||
- [Rust By Example](https://doc.rust-lang.org/rust-by-example/index.html) - Learn Rust by solving little exercises! It's almost like `rustlings`, but online
|
||||
@@ -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
|
||||
@@ -33,7 +34,7 @@ This will install Rustlings and give you access to the `rustlings` command. Run
|
||||
|
||||
## Windows
|
||||
|
||||
First, set `ExecutionPolicy` to `RemoteSigned`:
|
||||
In PowerShell, set `ExecutionPolicy` to `RemoteSigned`:
|
||||
|
||||
```ps
|
||||
Set-ExecutionPolicy RemoteSigned
|
||||
@@ -42,11 +43,17 @@ Set-ExecutionPolicy RemoteSigned
|
||||
Then, you can run:
|
||||
|
||||
```ps
|
||||
Invoke-WebRequest https://git.io/rustlings-win | Select-Object -ExpandProperty Content | Out-File $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1
|
||||
Start-BitsTransfer -Source https://git.io/rustlings-win -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1
|
||||
```
|
||||
|
||||
To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it.
|
||||
|
||||
## Browser:
|
||||
|
||||
[Run on Repl.it](https://repl.it/github/rust-lang/rustlings)
|
||||
|
||||
[Open in Gitpod](https://gitpod.io/#https://github.com/rust-lang/rustlings)
|
||||
|
||||
## Manually
|
||||
|
||||
Basically: Clone the repository, checkout to the latest tag, run `cargo install`.
|
||||
@@ -54,7 +61,7 @@ Basically: Clone the repository, checkout to the latest tag, run `cargo install`
|
||||
```bash
|
||||
git clone https://github.com/rust-lang/rustlings
|
||||
cd rustlings
|
||||
git checkout tags/2.2.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest)
|
||||
git checkout tags/4.3.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest)
|
||||
cargo install --force --path .
|
||||
```
|
||||
|
||||
@@ -69,7 +76,7 @@ Then, same as above, run `rustlings` to get started.
|
||||
|
||||
The exercises are sorted by topic and can be found in the subdirectory `rustlings/exercises/<topic>`. For every topic there is an additional README file with some resources to get you started on the topic. We really recommend that you have a look at them before you start.
|
||||
|
||||
The task is simple. Most exercises contain an error that keep it from compiling, and it's up to you to fix it! Some exercises are also run as tests, but rustlings handles them all the same. To run the exercises in the recommended order, execute:
|
||||
The task is simple. Most exercises contain an error that keeps them from compiling, and it's up to you to fix it! Some exercises are also run as tests, but rustlings handles them all the same. To run the exercises in the recommended order, execute:
|
||||
|
||||
```bash
|
||||
rustlings watch
|
||||
@@ -98,7 +105,36 @@ rustlings hint myExercise1
|
||||
|
||||
## Testing yourself
|
||||
|
||||
After every couple of sections, there will be a test that'll test your knowledge on a bunch of sections at once. These tests are found in `exercises/testN.rs`.
|
||||
After every couple of sections, there will be a quiz that'll test your knowledge on a bunch of sections at once. These quizzes are found in `exercises/quizN.rs`.
|
||||
|
||||
## Continuing On
|
||||
|
||||
Once you've completed Rustlings, put your new knowledge to good use! Continue practicing your Rust skills by building your own projects, contributing to Rustlings, or finding other open-source projects to contribute to.
|
||||
|
||||
If you'd like to uninstall Rustlings, you can do so by invoking cargo and removing the rustlings directory:
|
||||
|
||||
```bash
|
||||
cargo uninstall rustlings
|
||||
rm -r rustlings/ # or on Windows: rmdir /s rustlings
|
||||
```
|
||||
|
||||
## 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
|
||||
for you:
|
||||
|
||||
``` bash
|
||||
rm -rf rustlings # or your custom folder name, if you chose and or renamed it
|
||||
```
|
||||
|
||||
Second, since Rustlings got installed via `cargo install`, it's only reasonable to assume that you can also remove it using Cargo, and
|
||||
exactly that is the case. Run `cargo uninstall` to remove the `rustlings` binary:
|
||||
|
||||
``` bash
|
||||
cargo uninstall rustlings
|
||||
```
|
||||
|
||||
Now you should be done!
|
||||
|
||||
## Completion
|
||||
|
||||
@@ -122,7 +158,106 @@ 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 || Goulding)</b></sub></a><br /><a href="https://github.com/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/rustlings/commits?author=jrvidal" title="Code">💻</a> <a href="https://github.com/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/rustlings/commits?author=AbdouSeck" title="Code">💻</a> <a href="#content-AbdouSeck" title="Content">🖋</a> <a href="https://github.com/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/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/rust-lang/rustlings/commits?author=saidaspen" title="Code">💻</a> <a href="#content-saidaspen" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/uce"><img src="https://avatars3.githubusercontent.com/u/1756620?v=4" width="100px;" alt=""/><br /><sub><b>Ufuk Celebi</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=uce" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/lebedevsergey"><img src="https://avatars2.githubusercontent.com/u/7325764?v=4" width="100px;" alt=""/><br /><sub><b>lebedevsergey</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=lebedevsergey" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/avrong"><img src="https://avatars2.githubusercontent.com/u/6342851?v=4" width="100px;" alt=""/><br /><sub><b>Aleksei Trifonov</b></sub></a><br /><a href="#content-avrong" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://drn.ie"><img src="https://avatars2.githubusercontent.com/u/411136?v=4" width="100px;" alt=""/><br /><sub><b>Darren Meehan</b></sub></a><br /><a href="#content-Darrenmeehan" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/jihchi"><img src="https://avatars1.githubusercontent.com/u/87983?v=4" width="100px;" alt=""/><br /><sub><b>Jihchi Lee</b></sub></a><br /><a href="#content-jihchi" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/bertonha"><img src="https://avatars3.githubusercontent.com/u/1225902?v=4" width="100px;" alt=""/><br /><sub><b>Christofer Bertonha</b></sub></a><br /><a href="#content-bertonha" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/apatniv"><img src="https://avatars2.githubusercontent.com/u/22565917?v=4" width="100px;" alt=""/><br /><sub><b>Vivek Bharath Akupatni</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=apatniv" title="Code">💻</a> <a href="https://github.com/rust-lang/rustlings/commits?author=apatniv" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/DiD92"><img src="https://avatars3.githubusercontent.com/u/6002416?v=4" width="100px;" alt=""/><br /><sub><b>Dídac Sementé Fernández</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=DiD92" title="Code">💻</a> <a href="#content-DiD92" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/wrobstory"><img src="https://avatars3.githubusercontent.com/u/2601457?v=4" width="100px;" alt=""/><br /><sub><b>Rob Story</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=wrobstory" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/siobhanjacobson"><img src="https://avatars2.githubusercontent.com/u/28983835?v=4" width="100px;" alt=""/><br /><sub><b>Siobhan Jacobson</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=siobhanjacobson" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://www.linkedin.com/in/evancarroll/"><img src="https://avatars2.githubusercontent.com/u/19922?v=4" width="100px;" alt=""/><br /><sub><b>Evan Carroll</b></sub></a><br /><a href="#content-EvanCarroll" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://www.jawaadmahmood.com"><img src="https://avatars3.githubusercontent.com/u/95606?v=4" width="100px;" alt=""/><br /><sub><b>Jawaad Mahmood</b></sub></a><br /><a href="#content-jmahmood" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/GaurangTandon"><img src="https://avatars1.githubusercontent.com/u/6308683?v=4" width="100px;" alt=""/><br /><sub><b>Gaurang Tandon</b></sub></a><br /><a href="#content-GaurangTandon" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/dev-cyprium"><img src="https://avatars1.githubusercontent.com/u/6002628?v=4" width="100px;" alt=""/><br /><sub><b>Stefan Kupresak</b></sub></a><br /><a href="#content-dev-cyprium" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/greg-el"><img src="https://avatars3.githubusercontent.com/u/45019882?v=4" width="100px;" alt=""/><br /><sub><b>Greg Leonard</b></sub></a><br /><a href="#content-greg-el" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://ryanpcmcquen.org"><img src="https://avatars3.githubusercontent.com/u/772937?v=4" width="100px;" alt=""/><br /><sub><b>Ryan McQuen</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=ryanpcmcquen" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/AnnikaCodes"><img src="https://avatars3.githubusercontent.com/u/56906084?v=4" width="100px;" alt=""/><br /><sub><b>Annika</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/pulls?q=is%3Apr+reviewed-by%3AAnnikaCodes" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://darnuria.eu"><img src="https://avatars1.githubusercontent.com/u/2827553?v=4" width="100px;" alt=""/><br /><sub><b>Axel Viala</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=darnuria" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://sazid.github.io"><img src="https://avatars1.githubusercontent.com/u/2370167?v=4" width="100px;" alt=""/><br /><sub><b>Mohammed Sazid Al Rashid</b></sub></a><br /><a href="#content-sazid" title="Content">🖋</a> <a href="https://github.com/rust-lang/rustlings/commits?author=sazid" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://codingthemsoftly.com"><img src="https://avatars1.githubusercontent.com/u/17479099?v=4" width="100px;" alt=""/><br /><sub><b>Caleb Webber</b></sub></a><br /><a href="#maintenance-seeplusplus" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/pcn"><img src="https://avatars2.githubusercontent.com/u/1056756?v=4" width="100px;" alt=""/><br /><sub><b>Peter N</b></sub></a><br /><a href="#maintenance-pcn" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/seancad"><img src="https://avatars1.githubusercontent.com/u/47405611?v=4" width="100px;" alt=""/><br /><sub><b>seancad</b></sub></a><br /><a href="#maintenance-seancad" title="Maintenance">🚧</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!
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
Thanks for installing Rustlings!
|
||||
|
||||
Is this your first time?
|
||||
Is this your first time? Don't worry, Rustlings was made for beginners! We are
|
||||
going to teach you a lot of things about Rust, but before we can get
|
||||
started, here's a couple of notes about how Rustlings operates:
|
||||
|
||||
Let's make sure you're up to speed:
|
||||
- You have Rust installed, preferably via `rustup`
|
||||
- You have `~/.cargo/bin` added to your PATH variable
|
||||
- You have cloned this repository (https://github.com/rust-lang/rustlings)
|
||||
- You have installed Rust language support for your editor
|
||||
- You have locally installed the `rustlings` command by running an
|
||||
installation script or manually executing:
|
||||
1. The central concept behind Rustlings is that you solve exercises. These
|
||||
exercises usually have some sort of syntax error in them, which will cause
|
||||
them to fail compliation or testing. Sometimes there's a logic error instead
|
||||
of a syntax error. No matter what error, it's your job to find it and fix it!
|
||||
You'll know when you fixed it because then, the exercise will compile and
|
||||
Rustlings will be able to move on to the next exercise.
|
||||
2. If you run Rustlings in watch mode (which we recommend), it'll automatically
|
||||
start with the first exercise. Don't get confused by an error message popping
|
||||
up as soon as you run Rustlings! This is part of the exercise that you're
|
||||
supposed to solve, so open the exercise file in an editor and start your
|
||||
detective work!
|
||||
3. If you're stuck on an exercise, there is a helpful hint you can view by typing
|
||||
'hint' (in watch mode), or running `rustlings hint myexercise`.
|
||||
4. If an exercise doesn't make sense to you, feel free to open an issue on GitHub!
|
||||
(https://github.com/rust-lang/rustlings/issues/new). We look at every issue,
|
||||
and sometimes, other learners do too so you can help each other out!
|
||||
|
||||
cargo install --force --path .
|
||||
|
||||
If you've done all of this (or even most of it), congrats! You're ready
|
||||
to start working with Rust.
|
||||
|
||||
To get started, run `rustlings watch` in order to get the first exercise.
|
||||
Make sure to have your editor open!
|
||||
Got all that? Great! To get started, run `rustlings watch` in order to get the first
|
||||
exercise. Make sure to have your editor open!
|
||||
|
||||
24
exercises/README.md
Normal file
24
exercises/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Exercise to Book Chapter mapping
|
||||
|
||||
| Exercise | Book Chapter |
|
||||
|------------------------|--------------|
|
||||
| variables | §3.1 |
|
||||
| functions | §3.3 |
|
||||
| if | §3.5 |
|
||||
| move_semantics | §4.1 |
|
||||
| primitive_types | §4.3 |
|
||||
| structs | §5.1 |
|
||||
| enums | §6 |
|
||||
| modules | §7.2 |
|
||||
| collections | §8.1 |
|
||||
| strings | §8.2 |
|
||||
| error_handling | §9 |
|
||||
| generics | §10 |
|
||||
| option | §10.1 |
|
||||
| traits | §10.2 |
|
||||
| tests | §11.1 |
|
||||
| standard_library_types | §13.2 |
|
||||
| threads | §16.1 |
|
||||
| macros | §19.6 |
|
||||
| clippy | n/a |
|
||||
| conversions | n/a |
|
||||
8
exercises/clippy/README.md
Normal file
8
exercises/clippy/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
### Clippy
|
||||
|
||||
The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code.
|
||||
|
||||
If you used the installation script for Rustlings, Clippy should be already installed.
|
||||
If not you can install it manually via `rustup component add clippy`.
|
||||
|
||||
For more information about Clippy lints, please see [their documentation page](https://rust-lang.github.io/rust-clippy/master/).
|
||||
17
exercises/clippy/clippy1.rs
Normal file
17
exercises/clippy/clippy1.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
// clippy1.rs
|
||||
// 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
|
||||
|
||||
fn main() {
|
||||
let x = 1.2331f64;
|
||||
let y = 1.2332f64;
|
||||
if y != x {
|
||||
println!("Success!");
|
||||
}
|
||||
}
|
||||
13
exercises/clippy/clippy2.rs
Normal file
13
exercises/clippy/clippy2.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
// clippy2.rs
|
||||
// Make me compile! Execute `rustlings hint clippy2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let mut res = 42;
|
||||
let option = Some(12);
|
||||
for x in option {
|
||||
res += x;
|
||||
}
|
||||
println!("{}", res);
|
||||
}
|
||||
20
exercises/collections/README.md
Normal file
20
exercises/collections/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
### Collections
|
||||
|
||||
Rust’s standard library includes a number of very useful data
|
||||
structures called collections. Most other data types represent one
|
||||
specific value, but collections can contain multiple values. Unlike
|
||||
the built-in array and tuple types, the data these collections point
|
||||
to is stored on the heap, which means the amount of data does not need
|
||||
to be known at compile time and can grow or shrink as the program
|
||||
runs.
|
||||
|
||||
This exercise will get you familiar with two fundamental data
|
||||
structures that are used very often in Rust programs:
|
||||
|
||||
* A *vector* allows you to store a variable number of values next to
|
||||
each other.
|
||||
* A *hash map* allows you to associate a value with a particular key.
|
||||
You may also know this by the names *map* in C++, *dictionary* in
|
||||
Python or an *associative array* in other languages.
|
||||
|
||||
[Rust book chapter](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html)
|
||||
46
exercises/collections/hashmap1.rs
Normal file
46
exercises/collections/hashmap1.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
// hashmap1.rs
|
||||
// A basket of fruits in the form of a hash map needs to be defined.
|
||||
// The key represents the name of the fruit and the value represents
|
||||
// how many of that particular fruit is in the basket. You have to put
|
||||
// at least three different types of fruits (e.g apple, banana, mango)
|
||||
// in the basket and the total count of all the fruits should be at
|
||||
// least five.
|
||||
//
|
||||
// Make me compile and pass the tests!
|
||||
//
|
||||
// Execute the command `rustlings hint collections3` if you need
|
||||
// hints.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn fruit_basket() -> HashMap<String, u32> {
|
||||
let mut basket = // TODO: declare your hash map here.
|
||||
|
||||
// Two bananas are already given for you :)
|
||||
basket.insert(String::from("banana"), 2);
|
||||
|
||||
// TODO: Put more fruits in your basket here.
|
||||
|
||||
basket
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn at_least_three_types_of_fruits() {
|
||||
let basket = fruit_basket();
|
||||
assert!(basket.len() >= 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn at_least_five_fruits() {
|
||||
let basket = fruit_basket();
|
||||
assert!(basket
|
||||
.values()
|
||||
.sum::<u32>() >= 5);
|
||||
}
|
||||
}
|
||||
83
exercises/collections/hashmap2.rs
Normal file
83
exercises/collections/hashmap2.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
// hashmap2.rs
|
||||
|
||||
// A basket of fruits in the form of a hash map is given. The key
|
||||
// represents the name of the fruit and the value represents how many
|
||||
// of that particular fruit is in the basket. You have to put *MORE
|
||||
// THAN 11* fruits in the basket. Three types of fruits - Apple (4),
|
||||
// Mango (2) and Lichi (5) are already given in the basket. You are
|
||||
// not allowed to insert any more of these fruits!
|
||||
//
|
||||
// Make me pass the tests!
|
||||
//
|
||||
// Execute the command `rustlings hint collections4` if you need
|
||||
// hints.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
enum Fruit {
|
||||
Apple,
|
||||
Banana,
|
||||
Mango,
|
||||
Lichi,
|
||||
Pineapple,
|
||||
}
|
||||
|
||||
fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
||||
let fruit_kinds = vec![
|
||||
Fruit::Apple,
|
||||
Fruit::Banana,
|
||||
Fruit::Mango,
|
||||
Fruit::Lichi,
|
||||
Fruit::Pineapple,
|
||||
];
|
||||
|
||||
for fruit in fruit_kinds {
|
||||
// TODO: Put new fruits if not already present. Note that you
|
||||
// are not allowed to put any type of fruit that's already
|
||||
// present!
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn get_fruit_basket() -> HashMap<Fruit, u32> {
|
||||
let mut basket = HashMap::<Fruit, u32>::new();
|
||||
basket.insert(Fruit::Apple, 4);
|
||||
basket.insert(Fruit::Mango, 2);
|
||||
basket.insert(Fruit::Lichi, 5);
|
||||
|
||||
basket
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_given_fruits_are_not_modified() {
|
||||
let mut basket = get_fruit_basket();
|
||||
fruit_basket(&mut basket);
|
||||
assert_eq!(*basket.get(&Fruit::Apple).unwrap(), 4);
|
||||
assert_eq!(*basket.get(&Fruit::Mango).unwrap(), 2);
|
||||
assert_eq!(*basket.get(&Fruit::Lichi).unwrap(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn at_least_five_types_of_fruits() {
|
||||
let mut basket = get_fruit_basket();
|
||||
fruit_basket(&mut basket);
|
||||
let count_fruit_kinds = basket.len();
|
||||
assert!(count_fruit_kinds == 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn greater_than_eleven_fruits() {
|
||||
let mut basket = get_fruit_basket();
|
||||
fruit_basket(&mut basket);
|
||||
let count = basket
|
||||
.values()
|
||||
.sum::<u32>();
|
||||
assert!(count > 11);
|
||||
}
|
||||
}
|
||||
25
exercises/collections/vec1.rs
Normal file
25
exercises/collections/vec1.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
// vec1.rs
|
||||
// Your task is to create a `Vec` which holds the exact same elements
|
||||
// as in the array `a`.
|
||||
// Make me compile and pass the test!
|
||||
// Execute the command `rustlings hint collections1` if you need hints.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
||||
let a = [10, 20, 30, 40]; // a plain array
|
||||
let v = // TODO: declare your vector here with the macro for vectors
|
||||
|
||||
(a, v)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_array_and_vec_similarity() {
|
||||
let (a, v) = array_and_vec();
|
||||
assert_eq!(a, v[..]);
|
||||
}
|
||||
}
|
||||
38
exercises/collections/vec2.rs
Normal file
38
exercises/collections/vec2.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// vec2.rs
|
||||
// A Vec of even numbers is given. Your task is to complete the loop
|
||||
// so that each number in the Vec is multiplied by 2.
|
||||
//
|
||||
// Make me pass the test!
|
||||
//
|
||||
// Execute the command `rustlings hint collections2` if you need
|
||||
// hints.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
|
||||
for i in v.iter_mut() {
|
||||
// TODO: Fill this up so that each element in the Vec `v` is
|
||||
// multiplied by 2.
|
||||
}
|
||||
|
||||
// At this point, `v` should be equal to [4, 8, 12, 16, 20].
|
||||
v
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_vec_loop() {
|
||||
let v: Vec<i32> = (1..).filter(|x| x % 2 == 0).take(5).collect();
|
||||
let ans = vec_loop(v.clone());
|
||||
|
||||
assert_eq!(
|
||||
ans,
|
||||
v.iter()
|
||||
.map(|x| x * 2)
|
||||
.collect::<Vec<i32>>()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
// and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Obtain the number of bytes (not characters) in the given argument
|
||||
// Add the AsRef trait appropriately as a trait bound
|
||||
fn byte_counter<T>(arg: T) -> usize {
|
||||
arg.as_ref().as_bytes().len()
|
||||
}
|
||||
|
||||
// I AM NOT DONE
|
||||
// Obtain the number of characters (not bytes) in the given argument
|
||||
// Add the AsRef trait appropriately as a trait bound
|
||||
fn char_counter<T>(arg: T) -> usize {
|
||||
@@ -37,4 +37,16 @@ mod tests {
|
||||
let s = "Cafe au lait";
|
||||
assert_eq!(char_counter(s), byte_counter(s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_counts_using_string() {
|
||||
let s = String::from("Café au lait");
|
||||
assert_ne!(char_counter(s.clone()), byte_counter(s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_counts_using_string() {
|
||||
let s = String::from("Cafe au lait");
|
||||
assert_eq!(char_counter(s.clone()), byte_counter(s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ impl Default for Person {
|
||||
}
|
||||
}
|
||||
|
||||
// I AM NOT DONE
|
||||
// Your task is to complete this implementation
|
||||
// in order for the line `let p = Person::from("Mark,20")` to compile
|
||||
// Please note that you'll need to parse the age component into a `usize`
|
||||
@@ -29,9 +28,13 @@ 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
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
impl From<&str> for Person {
|
||||
fn from(s: &str) -> Person {
|
||||
}
|
||||
@@ -70,4 +73,46 @@ mod tests {
|
||||
assert_eq!(p.name, "Mark");
|
||||
assert_eq!(p.age, 20);
|
||||
}
|
||||
#[test]
|
||||
fn test_bad_age() {
|
||||
// Test that "Mark,twenty" will return the default person due to an error in parsing age
|
||||
let p = Person::from("Mark,twenty");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ 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
|
||||
// with something like `"4".parse::<usize>()`.
|
||||
// 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 +41,45 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,70 +2,153 @@
|
||||
// Basically, this is the same as From. The main difference is that this should return a Result type
|
||||
// instead of the target type itself.
|
||||
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
||||
use std::convert::{TryInto, TryFrom};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Person {
|
||||
name: String,
|
||||
age: usize,
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Color {
|
||||
red: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
}
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Your task is to complete this implementation
|
||||
// in order for the line `let p = Person::try_from("Mark,20")` to compile
|
||||
// and return an Ok result of inner type Person.
|
||||
// Please note that you'll need to parse the age component into a `usize`
|
||||
// with something like `"4".parse::<usize>()`. The outcome of this needs to
|
||||
// be handled appropriately.
|
||||
// and return an Ok result of inner type Color.
|
||||
// You need to create an implementation for a tuple of three integers,
|
||||
// an array of three integers and a slice of integers.
|
||||
//
|
||||
// Steps:
|
||||
// 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
|
||||
// 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 {
|
||||
// Note that the implementation for tuple and array will be checked at compile time,
|
||||
// but the slice implementation needs to check the slice length!
|
||||
// Also note that correct RGB color values must be integers in the 0..=255 range.
|
||||
|
||||
// Tuple implementation
|
||||
impl TryFrom<(i16, i16, i16)> for Color {
|
||||
type Error = String;
|
||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||
}
|
||||
fn try_from(tuple: (i16, i16, i16)) -> Result<Self, Self::Error> {}
|
||||
}
|
||||
|
||||
// Array implementation
|
||||
impl TryFrom<[i16; 3]> for Color {
|
||||
type Error = String;
|
||||
fn try_from(arr: [i16; 3]) -> Result<Self, Self::Error> {}
|
||||
}
|
||||
|
||||
// Slice implementation
|
||||
impl TryFrom<&[i16]> for Color {
|
||||
type Error = String;
|
||||
fn try_from(slice: &[i16]) -> Result<Self, Self::Error> {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Use the `from` function
|
||||
let p1 = Person::try_from("Mark,20");
|
||||
// Since From is implemented for Person, we should be able to use Into
|
||||
let p2: Result<Person, _> = "Gerald,70".try_into();
|
||||
println!("{:?}", p1);
|
||||
println!("{:?}", p2);
|
||||
let c1 = Color::try_from((183, 65, 14));
|
||||
println!("{:?}", c1);
|
||||
|
||||
// Since From is implemented for Color, we should be able to use Into
|
||||
let c2: Result<Color, _> = [183, 65, 14].try_into();
|
||||
println!("{:?}", c2);
|
||||
|
||||
let v = vec![183, 65, 14];
|
||||
// With slice we should use `from` function
|
||||
let c3 = Color::try_from(&v[..]);
|
||||
println!("{:?}", c3);
|
||||
// or take slice within round brackets and use Into
|
||||
let c4: Result<Color, _> = (&v[..]).try_into();
|
||||
println!("{:?}", c4);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_bad_convert() {
|
||||
// Test that John is returned when bad string is provided
|
||||
let p = Person::try_from("");
|
||||
assert!(p.is_err());
|
||||
fn test_tuple_out_of_range_positive() {
|
||||
assert!(Color::try_from((256, 1000, 10000)).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_good_convert() {
|
||||
// Test that "Mark,20" works
|
||||
let p = Person::try_from("Mark,20");
|
||||
assert!(p.is_ok());
|
||||
let p = p.unwrap();
|
||||
assert_eq!(p.name, "Mark");
|
||||
assert_eq!(p.age, 20);
|
||||
fn test_tuple_out_of_range_negative() {
|
||||
assert!(Color::try_from((-1, -10, -256)).is_err());
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_panic_empty_input() {
|
||||
let p: Person = "".try_into().unwrap();
|
||||
fn test_tuple_sum() {
|
||||
assert!(Color::try_from((-1, 255, 255)).is_err());
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_panic_bad_age() {
|
||||
let p = Person::try_from("Mark,twenty").unwrap();
|
||||
fn test_tuple_correct() {
|
||||
let c: Result<Color, String> = (183, 65, 14).try_into();
|
||||
assert_eq!(
|
||||
c,
|
||||
Ok(Color {
|
||||
red: 183,
|
||||
green: 65,
|
||||
blue: 14
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn test_array_out_of_range_positive() {
|
||||
let c: Result<Color, String> = [1000, 10000, 256].try_into();
|
||||
assert!(c.is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_array_out_of_range_negative() {
|
||||
let c: Result<Color, String> = [-10, -256, -1].try_into();
|
||||
assert!(c.is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_array_sum() {
|
||||
let c: Result<Color, String> = [-1, 255, 255].try_into();
|
||||
assert!(c.is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_array_correct() {
|
||||
let c: Result<Color, String> = [183, 65, 14].try_into();
|
||||
assert_eq!(
|
||||
c,
|
||||
Ok(Color {
|
||||
red: 183,
|
||||
green: 65,
|
||||
blue: 14
|
||||
})
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_out_of_range_positive() {
|
||||
let arr = [10000, 256, 1000];
|
||||
assert!(Color::try_from(&arr[..]).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_out_of_range_negative() {
|
||||
let arr = [-256, -1, -10];
|
||||
assert!(Color::try_from(&arr[..]).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_sum() {
|
||||
let arr = [-1, 255, 255];
|
||||
assert!(Color::try_from(&arr[..]).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_correct() {
|
||||
let v = vec![183, 65, 14];
|
||||
let c: Result<Color, String> = Color::try_from(&v[..]);
|
||||
assert_eq!(
|
||||
c,
|
||||
Ok(Color {
|
||||
red: 183,
|
||||
green: 65,
|
||||
blue: 14
|
||||
})
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_excess_length() {
|
||||
let v = vec![0, 0, 0, 0];
|
||||
assert!(Color::try_from(&v[..]).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_insufficient_length() {
|
||||
let v = vec![0, 0];
|
||||
assert!(Color::try_from(&v[..]).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
// Type casting in Rust is done via the usage of the `as` operator.
|
||||
// Please note that the `as` operator is not only used when type casting.
|
||||
// It also helps with renaming imports.
|
||||
//
|
||||
// The goal is to make sure that the division does not fail to compile
|
||||
// and returns the proper type.
|
||||
|
||||
// I AM NOT DONE
|
||||
// The goal is to make sure that the division does not fail to compile
|
||||
|
||||
fn average(values: &[f64]) -> f64 {
|
||||
let total = values
|
||||
.iter()
|
||||
.fold(0.0, |a, b| a + b);
|
||||
let total = values.iter().fold(0.0, |a, b| a + b);
|
||||
total / values.len()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let values = [3.5, 0.3, 13.0, 11.7];
|
||||
println!("{}", average(&values));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn returns_proper_type_and_value() {
|
||||
assert_eq!(average(&[3.5, 0.3, 13.0, 11.7]), 7.125);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
### Enums
|
||||
|
||||
Rust allows you to define types called "enums" which enumerate possible values.
|
||||
Rust allows you to define types called "enums" which enumerate possible values.
|
||||
Enums are a feature in many languages, but their capabilities differ in each language. Rust’s enums are most similar to algebraic data types in functional languages, such as F#, OCaml, and Haskell.
|
||||
Useful in combination with enums is Rust's "pattern matching" facility, which makes it easy to run different code for different values of an enumeration.
|
||||
Useful in combination with enums is Rust's "pattern matching" facility, which makes it easy to run different code for different values of an enumeration.
|
||||
|
||||
#### Book Sections
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ impl Message {
|
||||
|
||||
fn main() {
|
||||
let messages = [
|
||||
Message::Move{ x: 10, y: 30 },
|
||||
Message::Move { x: 10, y: 30 },
|
||||
Message::Echo(String::from("hello world")),
|
||||
Message::ChangeColor(200, 255, 255),
|
||||
Message::Quit
|
||||
Message::Quit,
|
||||
];
|
||||
|
||||
for message in &messages {
|
||||
|
||||
@@ -9,13 +9,13 @@ enum Message {
|
||||
|
||||
struct Point {
|
||||
x: u8,
|
||||
y: u8
|
||||
y: u8,
|
||||
}
|
||||
|
||||
struct State {
|
||||
color: (u8, u8, u8),
|
||||
position: Point,
|
||||
quit: bool
|
||||
quit: bool,
|
||||
}
|
||||
|
||||
impl State {
|
||||
@@ -46,14 +46,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_match_message_call() {
|
||||
let mut state = State{
|
||||
let mut state = State {
|
||||
quit: false,
|
||||
position: Point{ x: 0, y: 0 },
|
||||
color: (0, 0, 0)
|
||||
position: Point { x: 0, y: 0 },
|
||||
color: (0, 0, 0),
|
||||
};
|
||||
state.process(Message::ChangeColor(255, 0, 255));
|
||||
state.process(Message::ChangeColor((255, 0, 255)));
|
||||
state.process(Message::Echo(String::from("hello world")));
|
||||
state.process(Message::Move{ x: 10, y: 15 });
|
||||
state.process(Message::Move(Point { x: 10, y: 15 }));
|
||||
state.process(Message::Quit);
|
||||
|
||||
assert_eq!(state.color, (255, 0, 255));
|
||||
@@ -61,5 +61,4 @@ mod tests {
|
||||
assert_eq!(state.position.y, 15);
|
||||
assert_eq!(state.quit, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
For this exercise check out the sections:
|
||||
- [Error Handling](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html)
|
||||
- [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html)
|
||||
- [Error Handling](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html)
|
||||
- [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html)
|
||||
|
||||
of the Rust Book.
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
// This is a bigger error exercise than the previous ones!
|
||||
// You can do it! :)
|
||||
//
|
||||
// Edit the `read_and_validate` function so that it compiles and
|
||||
// passes the tests... so many things could go wrong!
|
||||
// Edit the `read_and_validate` function ONLY. Don't create any Errors
|
||||
// that do not already exist.
|
||||
//
|
||||
// So many things could go wrong!
|
||||
//
|
||||
// - Reading from stdin could produce an io::Error
|
||||
// - Parsing the input could produce a num::ParseIntError
|
||||
@@ -30,6 +32,10 @@ fn read_and_validate(b: &mut dyn io::BufRead) -> Result<PositiveNonzeroInteger,
|
||||
answer
|
||||
}
|
||||
|
||||
//
|
||||
// Nothing below this needs to be modified
|
||||
//
|
||||
|
||||
// This is a test helper function that turns a &str into a BufReader.
|
||||
fn test_with_str(s: &str) -> Result<PositiveNonzeroInteger, Box<dyn error::Error>> {
|
||||
let mut b = io::BufReader::new(s.as_bytes());
|
||||
@@ -100,15 +106,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 {}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ fn main() {
|
||||
call_me(3);
|
||||
}
|
||||
|
||||
fn call_me(num) {
|
||||
fn call_me(num:) {
|
||||
for i in 0..num {
|
||||
println!("Ring! Call number {}", i + 1);
|
||||
}
|
||||
|
||||
7
exercises/generics/README.md
Normal file
7
exercises/generics/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### Generics
|
||||
|
||||
In this section you'll learn about saving yourself many lines of code with generics!
|
||||
|
||||
### Book Sections
|
||||
|
||||
- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html)
|
||||
9
exercises/generics/generics1.rs
Normal file
9
exercises/generics/generics1.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// This shopping list program isn't compiling!
|
||||
// Use your knowledge of generics to fix it.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let mut shopping_list: Vec<?> = Vec::new();
|
||||
shopping_list.push("milk");
|
||||
}
|
||||
29
exercises/generics/generics2.rs
Normal file
29
exercises/generics/generics2.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
// This powerful wrapper provides the ability to store a positive integer value.
|
||||
// Rewrite it using generics so that it supports wrapping ANY type.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
struct Wrapper {
|
||||
value: u32,
|
||||
}
|
||||
|
||||
impl Wrapper {
|
||||
pub fn new(value: u32) -> Self {
|
||||
Wrapper { value }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn store_u32_in_wrapper() {
|
||||
assert_eq!(Wrapper::new(42).value, 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn store_str_in_wrapper() {
|
||||
assert_eq!(Wrapper::new("Foo").value, "Foo");
|
||||
}
|
||||
}
|
||||
58
exercises/generics/generics3.rs
Normal file
58
exercises/generics/generics3.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
// An imaginary magical school has a new report card generation system written in Rust!
|
||||
// Currently the system only supports creating report cards where the student's grade
|
||||
// is represented numerically (e.g. 1.0 -> 5.5).
|
||||
// However, the school also issues alphabetical grades (A+ -> F-) and needs
|
||||
// to be able to print both types of report card!
|
||||
|
||||
// Make the necessary code changes in the struct ReportCard and the impl block
|
||||
// to support alphabetical report cards. Change the Grade in the second test to "A+"
|
||||
// to show that your changes allow alphabetical grades.
|
||||
|
||||
// Execute 'rustlings hint generics3' for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
pub struct ReportCard {
|
||||
pub grade: f32,
|
||||
pub student_name: String,
|
||||
pub student_age: u8,
|
||||
}
|
||||
|
||||
impl ReportCard {
|
||||
pub fn print(&self) -> String {
|
||||
format!("{} ({}) - achieved a grade of {}",
|
||||
&self.student_name, &self.student_age, &self.grade)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn generate_numeric_report_card() {
|
||||
let report_card = ReportCard {
|
||||
grade: 2.1,
|
||||
student_name: "Tom Wriggle".to_string(),
|
||||
student_age: 12,
|
||||
};
|
||||
assert_eq!(
|
||||
report_card.print(),
|
||||
"Tom Wriggle (12) - achieved a grade of 2.1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generate_alphabetic_report_card() {
|
||||
// TODO: Make sure to change the grade here after you finish the exercise.
|
||||
let report_card = ReportCard {
|
||||
grade: 2.1,
|
||||
student_name: "Gary Plotter".to_string(),
|
||||
student_age: 11,
|
||||
};
|
||||
assert_eq!(
|
||||
report_card.print(),
|
||||
"Gary Plotter (11) - achieved a grade of A+"
|
||||
);
|
||||
}
|
||||
}
|
||||
36
exercises/if/if2.rs
Normal file
36
exercises/if/if2.rs
Normal 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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
9
exercises/option/README.md
Normal file
9
exercises/option/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
### Option
|
||||
|
||||
#### Book Sections
|
||||
|
||||
To learn about Option<T>, check out these links:
|
||||
|
||||
- [Option Enum Format](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-enum-definitions)
|
||||
- [Option Module Documentation](https://doc.rust-lang.org/std/option/)
|
||||
- [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html)
|
||||
23
exercises/option/option1.rs
Normal file
23
exercises/option/option1.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
// option1.rs
|
||||
// Make me compile! Execute `rustlings hint option1` for hints
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// you can modify anything EXCEPT for this function's sig
|
||||
fn print_number(maybe_number: Option<u16>) {
|
||||
println!("printing: {}", maybe_number.unwrap());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
print_number(13);
|
||||
print_number(99);
|
||||
|
||||
let mut numbers: [Option<u16>; 5];
|
||||
for iter in 0..5 {
|
||||
let number_to_add: u16 = {
|
||||
((iter * 1235) + 2) / (4 * 16)
|
||||
};
|
||||
|
||||
numbers[iter as usize] = number_to_add;
|
||||
}
|
||||
}
|
||||
25
exercises/option/option2.rs
Normal file
25
exercises/option/option2.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
// option2.rs
|
||||
// Make me compile! Execute `rustlings hint option2` for hints
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let optional_value = Some(String::from("rustlings"));
|
||||
// TODO: Make this an if let statement whose value is "Some" type
|
||||
value = optional_value {
|
||||
println!("the value of optional value is: {}", value);
|
||||
} else {
|
||||
println!("The optional value doesn't contain anything!");
|
||||
}
|
||||
|
||||
let mut optional_values_vec: Vec<Option<i8>> = Vec::new();
|
||||
for x in 1..10 {
|
||||
optional_values_vec.push(Some(x));
|
||||
}
|
||||
|
||||
// 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
|
||||
value = optional_values_vec.pop() {
|
||||
println!("current value: {}", value);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// primitive_types3.rs
|
||||
// Create an array with at least 100 elements in it where the ??? is.
|
||||
// Create an array with at least 100 elements in it where the ??? is.
|
||||
// Execute `rustlings hint primitive_types3` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
// primitive_types6.rs
|
||||
// Use a tuple index to access the second element of `numbers`.
|
||||
// You can put this right into the `println!` where the ??? is.
|
||||
// You can put the expression for the second element where ??? is so that the test passes.
|
||||
// Execute `rustlings hint primitive_types6` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
#[test]
|
||||
fn indexing_tuple() {
|
||||
let numbers = (1, 2, 3);
|
||||
println!("The second number is {}", ???);
|
||||
// Replace below ??? with the tuple indexing syntax.
|
||||
let second = ???;
|
||||
|
||||
assert_eq!(2, second,
|
||||
"This is not the 2nd number in the tuple!")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// test1.rs
|
||||
// This is a test for the following sections:
|
||||
// quiz1.rs
|
||||
// This is a quiz for the following sections:
|
||||
// - Variables
|
||||
// - Functions
|
||||
|
||||
30
exercises/quiz2.rs
Normal file
30
exercises/quiz2.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
// quiz2.rs
|
||||
// This is a quiz for the following sections:
|
||||
// - Strings
|
||||
|
||||
// Ok, here are a bunch of values-- some are `String`s, some are `&str`s. Your
|
||||
// task is to call one of these two functions on each value depending on what
|
||||
// you think each value is. That is, add either `string_slice` or `string`
|
||||
// before the parentheses on each line. If you're right, it will compile!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn string_slice(arg: &str) {
|
||||
println!("{}", arg);
|
||||
}
|
||||
fn string(arg: String) {
|
||||
println!("{}", arg);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
???("blue");
|
||||
???("red".to_string());
|
||||
???(String::from("hi"));
|
||||
???("rust is fun!".to_owned());
|
||||
???("nice weather".into());
|
||||
???(format!("Interpolation {}", "Station"));
|
||||
???(&String::from("abc")[0..1]);
|
||||
???(" hello there ".trim());
|
||||
???("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||
???("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
// test3.rs
|
||||
// This is a test for the following sections:
|
||||
// quiz3.rs
|
||||
// This is a quiz for the following sections:
|
||||
// - Tests
|
||||
|
||||
// This test isn't testing our function -- make it do that in such a way that
|
||||
// This quiz isn't testing our function -- make it do that in such a way that
|
||||
// the test passes. Then write a second test that tests that we get the result
|
||||
// we expect to get when we call `times_two` with a negative number.
|
||||
// No hints, you can do this :)
|
||||
@@ -1,9 +1,9 @@
|
||||
// test4.rs
|
||||
// This test covers the sections:
|
||||
// quiz4.rs
|
||||
// This quiz covers the sections:
|
||||
// - Modules
|
||||
// - Macros
|
||||
|
||||
// Write a macro that passes the test! No hints this time, you can do it!
|
||||
// Write a macro that passes the quiz! No hints this time, you can do it!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
For the Box exercise check out the chapter [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html).
|
||||
|
||||
For the Arc exercise check out the chapter [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) of the Rust Book.
|
||||
|
||||
For the Iterator exercise check out the chapters [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) of the Rust Book and the [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/).
|
||||
Do not adjust your monitors-- iterators1.rs is indeed missing. Iterators is a challenging topic, so we're leaving space for a simpler exercise!
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#![forbid(unused_imports)] // Do not change this, (or the next) line.
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
@@ -20,7 +21,7 @@ fn main() {
|
||||
let mut sum = 0;
|
||||
while i < child_numbers.len() {
|
||||
sum += child_numbers[i];
|
||||
i += 5;
|
||||
i += 8;
|
||||
}
|
||||
println!("Sum of offset {} is {}", offset, sum);
|
||||
}));
|
||||
|
||||
56
exercises/standard_library_types/box1.rs
Normal file
56
exercises/standard_library_types/box1.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
// box1.rs
|
||||
//
|
||||
// At compile time, Rust needs to know how much space a type takes up. This becomes problematic
|
||||
// for recursive types, where a value can have as part of itself another value of the same type.
|
||||
// To get around the issue, we can use a `Box` - a smart pointer used to store data on the heap,
|
||||
// which also allows us to wrap a recursive type.
|
||||
//
|
||||
// The recursive type we're implementing in this exercise is the `cons list` - a data structure
|
||||
// frequently found in functional programming languages. Each item in a cons list contains two
|
||||
// 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!()`
|
||||
//
|
||||
// Note: the tests should not be changed
|
||||
//
|
||||
// Execute `rustlings hint box1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum List {
|
||||
Cons(i32, List),
|
||||
Nil,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("This is an empty cons list: {:?}", create_empty_list());
|
||||
println!(
|
||||
"This is a non-empty cons list: {:?}",
|
||||
create_non_empty_list()
|
||||
);
|
||||
}
|
||||
|
||||
pub fn create_empty_list() -> List {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn create_non_empty_list() -> List {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_create_empty_list() {
|
||||
assert_eq!(List::Nil, create_empty_list())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_non_empty_list() {
|
||||
assert_ne!(create_empty_list(), create_non_empty_list())
|
||||
}
|
||||
}
|
||||
24
exercises/standard_library_types/iterators1.rs
Normal file
24
exercises/standard_library_types/iterators1.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
// iterators1.rs
|
||||
//
|
||||
// Make me compile by filling in the `???`s
|
||||
//
|
||||
// When performing operations on elements within a collection, iterators are essential.
|
||||
// This module helps you get familiar with the structure of using an iterator and
|
||||
// how to go through elements within an iterable collection.
|
||||
//
|
||||
// Execute `rustlings hint iterators1` for hints :D
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main () {
|
||||
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
||||
|
||||
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
|
||||
|
||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
|
||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
|
||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
|
||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2.1
|
||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
|
||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
|
||||
}
|
||||
@@ -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 the 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
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ Rust has three struct types: a classic c struct, a tuple struct, and a unit stru
|
||||
|
||||
#### Book Sections
|
||||
|
||||
- [Structures](https://doc.rust-lang.org/rust-by-example/custom_types/structs.html)
|
||||
- [Structures](https://doc.rust-lang.org/book/ch05-01-defining-structs.html)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// structs2.rs
|
||||
// Address all the TODOs to make the tests pass!
|
||||
// No hints, just do it!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
71
exercises/structs/structs3.rs
Normal file
71
exercises/structs/structs3.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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 {
|
||||
sender_country: String,
|
||||
recipient_country: String,
|
||||
weight_in_grams: i32,
|
||||
}
|
||||
|
||||
impl Package {
|
||||
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
||||
if weight_in_grams <= 0 {
|
||||
// Something goes here...
|
||||
} else {
|
||||
return Package {
|
||||
sender_country,
|
||||
recipient_country,
|
||||
weight_in_grams,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn is_international(&self) -> ??? {
|
||||
// Something goes here...
|
||||
}
|
||||
|
||||
fn get_fees(&self, cents_per_gram: i32) -> ??? {
|
||||
// Something goes here...
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn fail_creating_weightless_package() {
|
||||
let sender_country = String::from("Spain");
|
||||
let recipient_country = String::from("Austria");
|
||||
|
||||
Package::new(sender_country, recipient_country, -2210);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_international_package() {
|
||||
let sender_country = String::from("Spain");
|
||||
let recipient_country = String::from("Russia");
|
||||
|
||||
let package = Package::new(sender_country, recipient_country, 1200);
|
||||
|
||||
assert!(package.is_international());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calculate_transport_fees() {
|
||||
let sender_country = String::from("Spain");
|
||||
let recipient_country = String::from("Spain");
|
||||
|
||||
let cents_per_gram = ???;
|
||||
|
||||
let package = Package::new(sender_country, recipient_country, 1500);
|
||||
|
||||
assert_eq!(package.get_fees(cents_per_gram), 4500);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
// test2.rs
|
||||
// This is a test for the following sections:
|
||||
// - Strings
|
||||
|
||||
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
|
||||
// task is to call one of these two functions on each value depending on what
|
||||
// you think each value is. That is, add either `string_slice` or `string`
|
||||
// before the parentheses on each line. If you're right, it will compile!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn string_slice(arg: &str) {
|
||||
println!("{}", arg);
|
||||
}
|
||||
fn string(arg: String) {
|
||||
println!("{}", arg);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
("blue");
|
||||
("red".to_string());
|
||||
(String::from("hi"));
|
||||
("rust is fun!".to_owned());
|
||||
("nice weather".into());
|
||||
(format!("Interpolation {}", "Station"));
|
||||
(&String::from("abc")[0..1]);
|
||||
(" hello there ".trim());
|
||||
("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||
("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||
}
|
||||
@@ -18,4 +18,9 @@ mod tests {
|
||||
fn is_true_when_even() {
|
||||
assert!();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_false_when_odd() {
|
||||
assert!();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// threads1.rs
|
||||
// Make this compile! Execute `rustlings hint threads1` for hints :)
|
||||
// The idea is the thread spawned on line 21 is completing jobs while the main thread is
|
||||
// monitoring progress until 10 jobs are completed. If you see 6 lines
|
||||
// monitoring progress until 10 jobs are completed. Because of the difference between the
|
||||
// spawned threads' sleep time, and the waiting threads sleep time, when you see 6 lines
|
||||
// of "waiting..." and the program ends without timing out when running,
|
||||
// you've got it :)
|
||||
|
||||
|
||||
20
exercises/traits/README.md
Normal file
20
exercises/traits/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
### Traits
|
||||
|
||||
A trait is a collection of methods.
|
||||
|
||||
Data types can implement traits. To do so, the methods making up the trait are defined for the data type. For example, the `String` data type implements the `From<&str>` trait. This allows a user to write `String::from("hello")`.
|
||||
|
||||
In this way, traits are somewhat similar to Java interfaces and C++ abstract classes.
|
||||
|
||||
Some additional common Rust traits include:
|
||||
|
||||
+ `Clone` (the `clone` method),
|
||||
+ `Display` (which allows formatted display via `{}`), and
|
||||
+ `Debug` (which allows formatted display via `{:?}`).
|
||||
|
||||
Because traits indicate shared behavior between data types, they are useful when writing generics.
|
||||
|
||||
|
||||
#### Book Sections
|
||||
|
||||
- [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html)
|
||||
@@ -1,21 +1,21 @@
|
||||
// traits1.rs
|
||||
// Time to implement some traits!
|
||||
//
|
||||
//
|
||||
// Your task is to implement the trait
|
||||
// `AppendBar' for the type `String'.
|
||||
//
|
||||
//
|
||||
// The trait AppendBar has only one function,
|
||||
// which appends "Bar" to any object
|
||||
// implementing this trait.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
trait AppendBar {
|
||||
fn append_bar(self) -> Self;
|
||||
}
|
||||
|
||||
impl AppendBar for String {
|
||||
//Add your code here
|
||||
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -40,5 +40,4 @@ mod tests {
|
||||
String::from("BarBar")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// traits2.rs
|
||||
//
|
||||
//
|
||||
// Your task is to implement the trait
|
||||
// `AppendBar' for a vector of strings.
|
||||
//
|
||||
//
|
||||
// To implement this trait, consider for
|
||||
// a moment what it means to 'append "Bar"'
|
||||
// to a vector of strings.
|
||||
//
|
||||
//
|
||||
// No boiler plate code this time,
|
||||
// you can do this!
|
||||
|
||||
@@ -18,9 +18,6 @@ trait AppendBar {
|
||||
|
||||
//TODO: Add your code here
|
||||
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -31,5 +28,4 @@ mod tests {
|
||||
assert_eq!(foo.pop().unwrap(), String::from("Bar"));
|
||||
assert_eq!(foo.pop().unwrap(), String::from("Foo"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
fn main() {
|
||||
let x = 3;
|
||||
println!("Number {}", x);
|
||||
x = 5;
|
||||
x = 5; // don't change this line
|
||||
println!("Number {}", x);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let number = "3";
|
||||
println!("Number {}", number);
|
||||
let number = "T-H-R-E-E";
|
||||
println!("Spell a Number : {}", number);
|
||||
number = 3;
|
||||
println!("Number {}", number);
|
||||
println!("Number plus two is : {}", number + 2);
|
||||
}
|
||||
|
||||
9
exercises/variables/variables6.rs
Normal file
9
exercises/variables/variables6.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// variables6.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);
|
||||
}
|
||||
795
info.toml
795
info.toml
@@ -52,24 +52,24 @@ 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."""
|
||||
|
||||
# IF
|
||||
|
||||
[[exercises]]
|
||||
name = "if1"
|
||||
path = "exercises/if/if1.rs"
|
||||
mode = "test"
|
||||
name = "variables6"
|
||||
path = "exercises/variables/variables6.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
It's possible to do this in one line if you would like!
|
||||
Some similar examples from other languages:
|
||||
- In C(++) this would be: `a > b ? a : b`
|
||||
- In Python this would be: `a if a > b else b`
|
||||
Remember in Rust that:
|
||||
- the `if` condition does not need to be surrounded by parentheses
|
||||
- `if`/`else` conditionals are expressions
|
||||
- Each condition is followed by a `{}` block."""
|
||||
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
|
||||
than 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#differences-between-variables-and-constants
|
||||
"""
|
||||
|
||||
# FUNCTIONS
|
||||
|
||||
@@ -121,254 +121,36 @@ They are not the same. There are two solutions:
|
||||
1. Add a `return` ahead of `num * num;`
|
||||
2. remove `;`, make it to be `num * num`"""
|
||||
|
||||
# IF
|
||||
|
||||
[[exercises]]
|
||||
name = "if1"
|
||||
path = "exercises/if/if1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
It's possible to do this in one line if you would like!
|
||||
Some similar examples from other languages:
|
||||
- In C(++) this would be: `a > b ? a : b`
|
||||
- In Python this would be: `a if a > b else b`
|
||||
Remember in Rust that:
|
||||
- the `if` condition does not need to be surrounded by parentheses
|
||||
- `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."""
|
||||
|
||||
# TEST 1
|
||||
|
||||
[[exercises]]
|
||||
name = "test1"
|
||||
path = "exercises/test1.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# PRIMITIVE TYPES
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types1"
|
||||
path = "exercises/primitive_types/primitive_types1.rs"
|
||||
mode = "compile"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types2"
|
||||
path = "exercises/primitive_types/primitive_types2.rs"
|
||||
mode = "compile"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types3"
|
||||
path = "exercises/primitive_types/primitive_types3.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
There's a shorthand to initialize Arrays with a certain size that does not
|
||||
require you to type in 100 items (but you certainly can if you want!).
|
||||
For example, you can do:
|
||||
let array = ["Are we there yet?"; 10];
|
||||
|
||||
Bonus: what are some other things you could have that would return true
|
||||
for `a.len() >= 100`?"""
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types4"
|
||||
path = "exercises/primitive_types/primitive_types4.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
|
||||
https://doc.rust-lang.org/book/ch04-03-slices.html
|
||||
and use the starting and ending indices of the items in the Array
|
||||
that you want to end up in the slice.
|
||||
|
||||
If you're curious why the first argument of `assert_eq!` does not
|
||||
have an ampersand for a reference since the second argument is a
|
||||
reference, take a look at the Deref coercions section of the book:
|
||||
https://doc.rust-lang.org/book/ch15-02-deref.html"""
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types5"
|
||||
path = "exercises/primitive_types/primitive_types5.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Take a look at the Data Types -> The Tuple Type section of the book:
|
||||
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type
|
||||
Particularly the part about destructuring (second to last example in the section).
|
||||
You'll need to make a pattern to bind `name` and `age` to the appropriate parts
|
||||
of the tuple. You can do it!!"""
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types6"
|
||||
path = "exercises/primitive_types/primitive_types6.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
While you could use a destructuring `let` for the tuple here, try
|
||||
indexing into it instead, as explained in the last example of the
|
||||
Data Types -> The Tuple Type section of the book:
|
||||
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type
|
||||
Now you have another tool in your toolbox!"""
|
||||
|
||||
# STRUCTS
|
||||
|
||||
[[exercises]]
|
||||
name = "structs1"
|
||||
path = "exercises/structs/structs1.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
[[exercises]]
|
||||
name = "structs2"
|
||||
path = "exercises/structs/structs2.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# STRINGS
|
||||
|
||||
[[exercises]]
|
||||
name = "strings1"
|
||||
path = "exercises/strings/strings1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
The `current_favorite_color` function is currently returning a string slice with the `'static`
|
||||
lifetime. We know this because the data of the string lives in our code itself -- it doesn't
|
||||
come from a file or user input or another program -- so it will live as long as our program
|
||||
lives. But it is still a string slice. There's one way to create a `String` by converting a
|
||||
string slice covered in the Strings chapter of the book, and another way that uses the `From`
|
||||
trait."""
|
||||
|
||||
[[exercises]]
|
||||
name = "strings2"
|
||||
path = "exercises/strings/strings2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Yes, it would be really easy to fix this by just changing the value bound to `word` to be a
|
||||
string slice instead of a `String`, wouldn't it?? There is a way to add one character to line
|
||||
9, though, that will coerce the `String` into a string slice."""
|
||||
|
||||
# TEST 2
|
||||
|
||||
[[exercises]]
|
||||
name = "test2"
|
||||
path = "exercises/test2.rs"
|
||||
mode = "compile"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# ENUMS
|
||||
|
||||
[[exercises]]
|
||||
name = "enums1"
|
||||
path = "exercises/enums/enums1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Hint: The declaration of the enumeration type has not been defined yet."""
|
||||
|
||||
[[exercises]]
|
||||
name = "enums2"
|
||||
path = "exercises/enums/enums2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Hint: you can create enumerations that have different variants with different types
|
||||
such as no data, anonymous structs, a single string, tuples, ...etc"""
|
||||
|
||||
[[exercises]]
|
||||
name = "enums3"
|
||||
path = "exercises/enums/enums3.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# TESTS
|
||||
|
||||
[[exercises]]
|
||||
name = "tests1"
|
||||
path = "exercises/tests/tests1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
You don't even need to write any code to test -- you can just test values and run that, even
|
||||
though you wouldn't do that in real life :) `assert!` is a macro that needs an argument.
|
||||
Depending on the value of the argument, `assert!` will do nothing (in which case the test will
|
||||
pass) or `assert!` will panic (in which case the test will fail). So try giving different values
|
||||
to `assert!` and see which ones compile, which ones pass, and which ones fail :)"""
|
||||
|
||||
[[exercises]]
|
||||
name = "tests2"
|
||||
path = "exercises/tests/tests2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Like the previous exercise, you don't need to write any code to get this test to compile and
|
||||
run. `assert_eq!` is a macro that takes two arguments and compares them. Try giving it two
|
||||
values that are equal! Try giving it two arguments that are different! Try giving it two values
|
||||
that are of different types! Try switching which argument comes first and which comes second!"""
|
||||
|
||||
[[exercises]]
|
||||
name = "tests3"
|
||||
path = "exercises/tests/tests3.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
You can call a function right where you're passing arguments to `assert!` -- so you could do
|
||||
something like `assert!(having_fun())`. If you want to check that you indeed get false, you
|
||||
can negate the result of what you're doing using `!`, like `assert!(!having_fun())`."""
|
||||
|
||||
# TEST 3
|
||||
|
||||
[[exercises]]
|
||||
name = "test3"
|
||||
path = "exercises/test3.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# MODULES
|
||||
|
||||
[[exercises]]
|
||||
name = "modules1"
|
||||
path = "exercises/modules/modules1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Everything is private in Rust by default-- but there's a keyword we can use
|
||||
to make something public! The compiler error should point to the thing that
|
||||
needs to be public."""
|
||||
|
||||
[[exercises]]
|
||||
name = "modules2"
|
||||
path = "exercises/modules/modules2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
The delicious_snacks module is trying to present an external
|
||||
interface (the `fruit` and `veggie` constants) that is different than
|
||||
its internal structure (the `fruits` and `veggies` modules and
|
||||
associated constants). It's almost there except for one keyword missing for
|
||||
each constant."""
|
||||
|
||||
# MACROS
|
||||
|
||||
[[exercises]]
|
||||
name = "macros1"
|
||||
path = "exercises/macros/macros1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
When you call a macro, you need to add something special compared to a
|
||||
regular function call. If you're stuck, take a look at what's inside
|
||||
`my_macro`."""
|
||||
|
||||
[[exercises]]
|
||||
name = "macros2"
|
||||
path = "exercises/macros/macros2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Macros don't quite play by the same rules as the rest of Rust, in terms of
|
||||
what's available where.
|
||||
|
||||
Unlike other things in Rust, the order of "where you define a macro" versus
|
||||
"where you use it" actually matters."""
|
||||
|
||||
[[exercises]]
|
||||
name = "macros3"
|
||||
path = "exercises/macros/macros3.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
In order to use a macro outside of its module, you need to do something
|
||||
special to the module to lift the macro out into its parent.
|
||||
|
||||
The same trick also works on "extern crate" statements for crates that have
|
||||
exported macros, if you've seen any of those around."""
|
||||
|
||||
[[exercises]]
|
||||
name = "macros4"
|
||||
path = "exercises/macros/macros4.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
You only need to add a single character to make this compile.
|
||||
The way macros are written, it wants to see something between each
|
||||
"macro arm", so it can separate them."""
|
||||
# TEST 4
|
||||
|
||||
[[exercises]]
|
||||
name = "test4"
|
||||
path = "exercises/test4.rs"
|
||||
name = "quiz1"
|
||||
path = "exercises/quiz1.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
@@ -428,6 +210,229 @@ So the end goal is to:
|
||||
- since we're not creating a new vec in `main` anymore, we need to create
|
||||
a new vec in `fill_vec`, similarly to the way we did in `main`"""
|
||||
|
||||
# PRIMITIVE TYPES
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types1"
|
||||
path = "exercises/primitive_types/primitive_types1.rs"
|
||||
mode = "compile"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types2"
|
||||
path = "exercises/primitive_types/primitive_types2.rs"
|
||||
mode = "compile"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types3"
|
||||
path = "exercises/primitive_types/primitive_types3.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
There's a shorthand to initialize Arrays with a certain size that does not
|
||||
require you to type in 100 items (but you certainly can if you want!).
|
||||
For example, you can do:
|
||||
let array = ["Are we there yet?"; 10];
|
||||
|
||||
Bonus: what are some other things you could have that would return true
|
||||
for `a.len() >= 100`?"""
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types4"
|
||||
path = "exercises/primitive_types/primitive_types4.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
|
||||
https://doc.rust-lang.org/book/ch04-03-slices.html
|
||||
and use the starting and ending indices of the items in the Array
|
||||
that you want to end up in the slice.
|
||||
|
||||
If you're curious why the first argument of `assert_eq!` does not
|
||||
have an ampersand for a reference since the second argument is a
|
||||
reference, take a look at the Deref coercions section of the book:
|
||||
https://doc.rust-lang.org/book/ch15-02-deref.html"""
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types5"
|
||||
path = "exercises/primitive_types/primitive_types5.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Take a look at the Data Types -> The Tuple Type section of the book:
|
||||
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type
|
||||
Particularly the part about destructuring (second to last example in the section).
|
||||
You'll need to make a pattern to bind `name` and `age` to the appropriate parts
|
||||
of the tuple. You can do it!!"""
|
||||
|
||||
[[exercises]]
|
||||
name = "primitive_types6"
|
||||
path = "exercises/primitive_types/primitive_types6.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
While you could use a destructuring `let` for the tuple here, try
|
||||
indexing into it instead, as explained in the last example of the
|
||||
Data Types -> The Tuple Type section of the book:
|
||||
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type
|
||||
Now you have another tool in your toolbox!"""
|
||||
|
||||
# STRUCTS
|
||||
|
||||
[[exercises]]
|
||||
name = "structs1"
|
||||
path = "exercises/structs/structs1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Rust has more than one type of struct. Three actually, all variants are used to package related data together.
|
||||
There are normal (or classic) structs. These are named collections of related data stored in fields.
|
||||
Tuple structs are basically just named tuples.
|
||||
Finally, Unit structs. These don't have and fields and are useful for generics.
|
||||
|
||||
In this exercise you need to complete and implement one of each kind.
|
||||
Read more about structs in The Book: https://doc.rust-lang.org/book/ch05-01-defining-structs.html"""
|
||||
|
||||
[[exercises]]
|
||||
name = "structs2"
|
||||
path = "exercises/structs/structs2.rs"
|
||||
mode = "test"
|
||||
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"""
|
||||
|
||||
# ENUMS
|
||||
|
||||
[[exercises]]
|
||||
name = "enums1"
|
||||
path = "exercises/enums/enums1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Hint: The declaration of the enumeration type has not been defined yet."""
|
||||
|
||||
[[exercises]]
|
||||
name = "enums2"
|
||||
path = "exercises/enums/enums2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Hint: you can create enumerations that have different variants with different types
|
||||
such as no data, anonymous structs, a single string, tuples, ...etc"""
|
||||
|
||||
[[exercises]]
|
||||
name = "enums3"
|
||||
path = "exercises/enums/enums3.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# MODULES
|
||||
|
||||
[[exercises]]
|
||||
name = "modules1"
|
||||
path = "exercises/modules/modules1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Everything is private in Rust by default-- but there's a keyword we can use
|
||||
to make something public! The compiler error should point to the thing that
|
||||
needs to be public."""
|
||||
|
||||
[[exercises]]
|
||||
name = "modules2"
|
||||
path = "exercises/modules/modules2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
The delicious_snacks module is trying to present an external
|
||||
interface (the `fruit` and `veggie` constants) that is different than
|
||||
its internal structure (the `fruits` and `veggies` modules and
|
||||
associated constants). It's almost there except for one keyword missing for
|
||||
each constant."""
|
||||
|
||||
# COLLECTIONS
|
||||
|
||||
[[exercises]]
|
||||
name = "collections1"
|
||||
path = "exercises/collections/vec1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
In Rust, there are two ways to define a Vector.
|
||||
1. One way is to use the `Vec::new()` function to create a new vector
|
||||
and fill it with the `push()` method.
|
||||
2. The second way, which is simpler is to use the `vec![]` macro and
|
||||
define your elements inside the square brackets.
|
||||
Check this chapter: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html
|
||||
of the Rust book to learn more.
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "collections2"
|
||||
path = "exercises/collections/vec2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Hint 1: `i` is each element from the Vec as they are being iterated.
|
||||
Can you try multiplying this?
|
||||
Hint 2: Check the suggestion from the compiler error ;)
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "collections3"
|
||||
path = "exercises/collections/hashmap1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Hint 1: Take a look at the return type of the function to figure out
|
||||
the type for the `basket`.
|
||||
Hint 2: Number of fruits should be at least 5. And you have to put
|
||||
at least three different types of fruits.
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "collections4"
|
||||
path = "exercises/collections/hashmap2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Use the `entry()` and `or_insert()` methods of `HashMap` to achieve this.
|
||||
Learn more at https://doc.rust-lang.org/stable/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value
|
||||
"""
|
||||
|
||||
# STRINGS
|
||||
|
||||
[[exercises]]
|
||||
name = "strings1"
|
||||
path = "exercises/strings/strings1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
The `current_favorite_color` function is currently returning a string slice with the `'static`
|
||||
lifetime. We know this because the data of the string lives in our code itself -- it doesn't
|
||||
come from a file or user input or another program -- so it will live as long as our program
|
||||
lives. But it is still a string slice. There's one way to create a `String` by converting a
|
||||
string slice covered in the Strings chapter of the book, and another way that uses the `From`
|
||||
trait."""
|
||||
|
||||
[[exercises]]
|
||||
name = "strings2"
|
||||
path = "exercises/strings/strings2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Yes, it would be really easy to fix this by just changing the value bound to `word` to be a
|
||||
string slice instead of a `String`, wouldn't it?? There is a way to add one character to line
|
||||
9, though, that will coerce the `String` into a string slice."""
|
||||
|
||||
# TEST 2
|
||||
|
||||
[[exercises]]
|
||||
name = "quiz2"
|
||||
path = "exercises/quiz2.rs"
|
||||
mode = "compile"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# ERROR HANDLING
|
||||
|
||||
[[exercises]]
|
||||
@@ -476,7 +481,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.
|
||||
|
||||
|
||||
@@ -507,18 +512,72 @@ get a warning if you don't handle a `Result` that you get in your
|
||||
function. Read more about that in the `std::result` module docs:
|
||||
https://doc.rust-lang.org/std/result/#results-must-be-used"""
|
||||
|
||||
# Generics
|
||||
|
||||
[[exercises]]
|
||||
name = "generics1"
|
||||
path = "exercises/generics/generics1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Vectors in rust make use of generics to create dynamically sized arrays of any type.
|
||||
You need to tell the compiler what type we are pushing onto this vector."""
|
||||
|
||||
[[exercises]]
|
||||
name = "generics2"
|
||||
path = "exercises/generics/generics2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Currently we are wrapping only values of type 'u32'.
|
||||
Maybe we could update the explicit references to this data type somehow?
|
||||
|
||||
If you are still stuck https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-method-definitions
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "generics3"
|
||||
path = "exercises/generics/generics3.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;"
|
||||
|
||||
This is definitely harder than the last two exercises! You need to think about not only making the
|
||||
ReportCard struct generic, but also the correct property - you will need to change the implementation
|
||||
of the struct slightly too...you can do it!
|
||||
"""
|
||||
|
||||
# OPTIONS / RESULTS
|
||||
|
||||
[[exercises]]
|
||||
name = "option1"
|
||||
path = "exercises/error_handling/option1.rs"
|
||||
mode = "test"
|
||||
path = "exercises/option/option1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Try using a `match` statement where the arms are `Some(thing)` and `None`.
|
||||
Or set a default value to print out if you get `None` by using the
|
||||
function `unwrap_or`.
|
||||
Or use an `if let` statement on the result of `pop()` to both destructure
|
||||
a `Some` value and only print out something if we have a value!"""
|
||||
Hint 1: Check out some functions of Option:
|
||||
is_some
|
||||
is_none
|
||||
unwrap
|
||||
|
||||
and:
|
||||
pattern matching
|
||||
|
||||
Hint 2: There are no sensible defaults for the value of an Array; the values need to be filled before use.
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "option2"
|
||||
path = "exercises/option/option2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
check out:
|
||||
https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html
|
||||
https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html
|
||||
|
||||
Remember that Options can be stacked in if let and while let.
|
||||
For example: Some(Some(variable)) = variable2
|
||||
|
||||
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "result1"
|
||||
@@ -529,8 +588,88 @@ hint = """
|
||||
It should be doing some checking, returning an `Err` result if those checks fail, and only
|
||||
returning an `Ok` result if those checks determine that everything is... okay :)"""
|
||||
|
||||
# TRAITS
|
||||
|
||||
[[exercises]]
|
||||
name = "traits1"
|
||||
path = "exercises/traits/traits1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
A discussion about Traits in Rust can be found at:
|
||||
https://doc.rust-lang.org/book/ch10-02-traits.html
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "traits2"
|
||||
path = "exercises/traits/traits2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Notice how the trait takes ownership of 'self',and returns `Self'.
|
||||
Try mutating the incoming string vector.
|
||||
|
||||
Vectors provide suitable methods for adding an element at the end. See
|
||||
the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html"""
|
||||
|
||||
# TESTS
|
||||
|
||||
[[exercises]]
|
||||
name = "tests1"
|
||||
path = "exercises/tests/tests1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
You don't even need to write any code to test -- you can just test values and run that, even
|
||||
though you wouldn't do that in real life :) `assert!` is a macro that needs an argument.
|
||||
Depending on the value of the argument, `assert!` will do nothing (in which case the test will
|
||||
pass) or `assert!` will panic (in which case the test will fail). So try giving different values
|
||||
to `assert!` and see which ones compile, which ones pass, and which ones fail :)"""
|
||||
|
||||
[[exercises]]
|
||||
name = "tests2"
|
||||
path = "exercises/tests/tests2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Like the previous exercise, you don't need to write any code to get this test to compile and
|
||||
run. `assert_eq!` is a macro that takes two arguments and compares them. Try giving it two
|
||||
values that are equal! Try giving it two arguments that are different! Try giving it two values
|
||||
that are of different types! Try switching which argument comes first and which comes second!"""
|
||||
|
||||
[[exercises]]
|
||||
name = "tests3"
|
||||
path = "exercises/tests/tests3.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
You can call a function right where you're passing arguments to `assert!` -- so you could do
|
||||
something like `assert!(having_fun())`. If you want to check that you indeed get false, you
|
||||
can negate the result of what you're doing using `!`, like `assert!(!having_fun())`."""
|
||||
|
||||
# TEST 3
|
||||
|
||||
[[exercises]]
|
||||
name = "quiz3"
|
||||
path = "exercises/quiz3.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# STANDARD LIBRARY TYPES
|
||||
|
||||
[[exercises]]
|
||||
name = "box1"
|
||||
path = "exercises/standard_library_types/box1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Step 1
|
||||
The compiler's message should help: since we cannot store the value of the actual type
|
||||
when working with recursive types, we need to store a reference (pointer) to its value.
|
||||
We should, therefore, place our `List` inside a `Box`. More details in the book here:
|
||||
https://doc.rust-lang.org/book/ch15-01-box.html#enabling-recursive-types-with-boxes
|
||||
|
||||
Step 2
|
||||
Creating an empty list should be fairly straightforward (hint: peek at the assertions).
|
||||
For a non-empty list keep in mind that we want to use our Cons "list builder".
|
||||
Although the current list is one of integers (i32), feel free to change the definition
|
||||
and try other types!
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "arc1"
|
||||
path = "exercises/standard_library_types/arc1.rs"
|
||||
@@ -543,6 +682,23 @@ inside the loop but still in the main thread.
|
||||
`child_numbers` should be a clone of the Arc of the numbers instead of a
|
||||
thread-local copy of the numbers."""
|
||||
|
||||
[[exercises]]
|
||||
name = "iterators1"
|
||||
path = "exercises/standard_library_types/iterators1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Step 1:
|
||||
We need to apply something to the collection `my_fav_fruits` before we start to go through
|
||||
it. What could that be? Take a look at the struct definition for a vector for inspiration:
|
||||
https://doc.rust-lang.org/std/vec/struct.Vec.html.
|
||||
Step 2 & step 2.1:
|
||||
Very similar to the lines above and below. You've got this!
|
||||
Step 3:
|
||||
An iterator goes through all elements in a collection, but what if we've run out of
|
||||
elements? What should we expect here? If you're stuck, take a look at
|
||||
https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas.
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "iterators2"
|
||||
path = "exercises/standard_library_types/iterators2.rs"
|
||||
@@ -581,32 +737,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."""
|
||||
|
||||
# TRAITS
|
||||
|
||||
[[exercises]]
|
||||
name = "traits1"
|
||||
path = "exercises/traits/traits1.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
A discussion about Traits in Rust can be found at:
|
||||
https://doc.rust-lang.org/1.30.0/book/second-edition/ch10-02-traits.html
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "traits2"
|
||||
path = "exercises/traits/traits2.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Notice how the trait takes ownership of 'self',and returns `Self'.
|
||||
Try mutating the incoming string vector.
|
||||
|
||||
Vectors provide suitable methods for adding an element at the end. See
|
||||
the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html"""
|
||||
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."""
|
||||
|
||||
# THREADS
|
||||
|
||||
@@ -647,12 +781,78 @@ If you've learned from the sample solutions, I encourage you to come
|
||||
back to this exercise and try it again in a few days to reinforce
|
||||
what you've learned :)"""
|
||||
|
||||
# MACROS
|
||||
|
||||
[[exercises]]
|
||||
name = "macros1"
|
||||
path = "exercises/macros/macros1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
When you call a macro, you need to add something special compared to a
|
||||
regular function call. If you're stuck, take a look at what's inside
|
||||
`my_macro`."""
|
||||
|
||||
[[exercises]]
|
||||
name = "macros2"
|
||||
path = "exercises/macros/macros2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Macros don't quite play by the same rules as the rest of Rust, in terms of
|
||||
what's available where.
|
||||
|
||||
Unlike other things in Rust, the order of "where you define a macro" versus
|
||||
"where you use it" actually matters."""
|
||||
|
||||
[[exercises]]
|
||||
name = "macros3"
|
||||
path = "exercises/macros/macros3.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
In order to use a macro outside of its module, you need to do something
|
||||
special to the module to lift the macro out into its parent.
|
||||
|
||||
The same trick also works on "extern crate" statements for crates that have
|
||||
exported macros, if you've seen any of those around."""
|
||||
|
||||
[[exercises]]
|
||||
name = "macros4"
|
||||
path = "exercises/macros/macros4.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
You only need to add a single character to make this compile.
|
||||
The way macros are written, it wants to see something between each
|
||||
"macro arm", so it can separate them."""
|
||||
|
||||
# TEST 4
|
||||
|
||||
[[exercises]]
|
||||
name = "quiz4"
|
||||
path = "exercises/quiz4.rs"
|
||||
mode = "test"
|
||||
hint = "No hints this time ;)"
|
||||
|
||||
# CLIPPY
|
||||
|
||||
[[exercises]]
|
||||
name = "clippy1"
|
||||
path = "exercises/clippy/clippy1.rs"
|
||||
mode = "clippy"
|
||||
hint = """
|
||||
Floating point calculations are usually imprecise, so asking if two values are exactly equal is asking for trouble"""
|
||||
|
||||
[[exercises]]
|
||||
name = "clippy2"
|
||||
path = "exercises/clippy/clippy2.rs"
|
||||
mode = "clippy"
|
||||
hint = """
|
||||
`for` loops over Option values are more clearly expressed as an `if let`"""
|
||||
|
||||
# TYPE CONVERSIONS
|
||||
|
||||
[[exercises]]
|
||||
name = "using_as"
|
||||
path = "exercises/conversions/using_as.rs"
|
||||
mode = "compile"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Use the `as` operator to cast one of the operands in the last line of the
|
||||
`average` function into the expected return type."""
|
||||
@@ -669,7 +869,7 @@ name = "try_from_into"
|
||||
path = "exercises/conversions/try_from_into.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Follow the steps provided right before the `From` implementation.
|
||||
Follow the steps provided right before the `TryFrom` implementation.
|
||||
You can also use the example at https://doc.rust-lang.org/std/convert/trait.TryFrom.html"""
|
||||
|
||||
[[exercises]]
|
||||
@@ -684,5 +884,6 @@ name = "from_str"
|
||||
path = "exercises/conversions/from_str.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
If you've already solved try_from_into.rs, then this is almost a copy-paste.
|
||||
Otherwise, go ahead and solve try_from_into.rs first."""
|
||||
The implementation of FromStr should return an Ok with a Person object,
|
||||
or an Err with a string if the string is not valid.
|
||||
This is almost like the `try_from_into` exercise."""
|
||||
|
||||
13
install.ps1
13
install.ps1
@@ -35,7 +35,7 @@ if (Get-Command cargo -ErrorAction SilentlyContinue) {
|
||||
function vercomp($v1, $v2) {
|
||||
if ($v1 -eq $v2) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
$v1 = $v1.Replace(".", "0")
|
||||
$v2 = $v2.Replace(".", "0")
|
||||
@@ -53,7 +53,7 @@ function vercomp($v1, $v2) {
|
||||
}
|
||||
|
||||
$rustVersion = $(rustc --version).Split(" ")[1]
|
||||
$minRustVersion = "1.31"
|
||||
$minRustVersion = "1.39"
|
||||
if ((vercomp $rustVersion $minRustVersion) -eq 2) {
|
||||
Write-Host "WARNING: Rust version is too old: $rustVersion - needs at least $minRustVersion"
|
||||
Write-Host "Please update Rust with 'rustup update'"
|
||||
@@ -72,6 +72,7 @@ if (!($LASTEXITCODE -eq 0)) {
|
||||
# but anyone running pwsh 5 will have to pass the argument.
|
||||
$version = Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/rust-lang/rustlings/releases/latest `
|
||||
| ConvertFrom-Json | Select-Object -ExpandProperty tag_name
|
||||
|
||||
Write-Host "Checking out version $version..."
|
||||
Set-Location $path
|
||||
git checkout -q tags/$version
|
||||
@@ -82,4 +83,12 @@ if (!(Get-Command rustlings -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "WARNING: Please check that you have '~/.cargo/bin' in your PATH environment variable!"
|
||||
}
|
||||
|
||||
# Checking whether Clippy is installed.
|
||||
# Due to a bug in Cargo, this must be done with Rustup: https://github.com/rust-lang/rustup/issues/1514
|
||||
$clippy = (rustup component list | Select-String "clippy" | Select-String "installed") | Out-String
|
||||
if (!$clippy) {
|
||||
Write-Host "Installing the 'cargo-clippy' executable..."
|
||||
rustup component add clippy
|
||||
}
|
||||
|
||||
Write-Host "All done! Run 'rustlings' to get started."
|
||||
|
||||
55
install.sh
55
install.sh
@@ -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() {
|
||||
@@ -71,7 +87,7 @@ function vercomp() {
|
||||
}
|
||||
|
||||
RustVersion=$(rustc --version | cut -d " " -f 2)
|
||||
MinRustVersion=1.31
|
||||
MinRustVersion=1.39
|
||||
vercomp $RustVersion $MinRustVersion
|
||||
if [ $? -eq 2 ]
|
||||
then
|
||||
@@ -86,17 +102,46 @@ 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']);")
|
||||
echo "Checking out version $Version..."
|
||||
cd $Path
|
||||
git checkout -q tags/$Version
|
||||
|
||||
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"
|
||||
|
||||
if [[ -z ${Version} ]]
|
||||
then
|
||||
echo "The latest tag version could not be fetched remotely."
|
||||
echo "Using the local git repository..."
|
||||
Version=$(ls -tr .git/refs/tags/ | tail -1)
|
||||
if [[ -z ${Version} ]]
|
||||
then
|
||||
echo "No valid tag version found"
|
||||
echo "Rustlings will be installed using the main branch"
|
||||
Version="main"
|
||||
else
|
||||
Version="tags/${Version}"
|
||||
fi
|
||||
else
|
||||
Version="tags/${Version}"
|
||||
fi
|
||||
|
||||
echo "Checking out version $Version..."
|
||||
git checkout -q ${Version}
|
||||
|
||||
echo "Installing the 'rustlings' executable..."
|
||||
cargo install --force --path .
|
||||
|
||||
if ! [ -x "$(command -v rustlings)" ]
|
||||
then
|
||||
echo "WARNING: Please check that you have '~/.cargo/bin' in your PATH environment variable!"
|
||||
echo "WARNING: Please check that you have '$CargoBin' in your PATH environment variable!"
|
||||
fi
|
||||
|
||||
# Checking whether Clippy is installed.
|
||||
# Due to a bug in Cargo, this must be done with Rustup: https://github.com/rust-lang/rustup/issues/1514
|
||||
Clippy=$(rustup component list | grep "clippy" | grep "installed")
|
||||
if [ -z "$Clippy" ]
|
||||
then
|
||||
echo "Installing the 'cargo-clippy' executable..."
|
||||
rustup component add clippy
|
||||
fi
|
||||
|
||||
echo "All done! Run 'rustlings' to get started."
|
||||
|
||||
167
src/exercise.rs
167
src/exercise.rs
@@ -1,24 +1,37 @@
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::fs::{remove_file, File};
|
||||
use std::fs::{self, remove_file, File};
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{self, Command, Output};
|
||||
use std::process::{self, Command};
|
||||
|
||||
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
|
||||
const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE";
|
||||
const CONTEXT: usize = 2;
|
||||
const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml";
|
||||
|
||||
// Get a temporary file name that is hopefully unique
|
||||
#[inline]
|
||||
fn temp_file() -> String {
|
||||
format!("./temp_{}", process::id())
|
||||
let thread_id: String = format!("{:?}", std::thread::current().id())
|
||||
.chars()
|
||||
.filter(|c| c.is_alphanumeric())
|
||||
.collect();
|
||||
|
||||
format!("./temp_{}_{}", process::id(), thread_id)
|
||||
}
|
||||
|
||||
// The mode of the exercise.
|
||||
#[derive(Deserialize, Copy, Clone)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Mode {
|
||||
// Indicates that the exercise should be compiled as a binary
|
||||
Compile,
|
||||
// Indicates that the exercise should be compiled as a test harness
|
||||
Test,
|
||||
// Indicates that the exercise should be linted with clippy
|
||||
Clippy,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -26,30 +39,74 @@ pub struct ExerciseList {
|
||||
pub exercises: Vec<Exercise>,
|
||||
}
|
||||
|
||||
// A representation of a rustlings exercise.
|
||||
// This is deserialized from the accompanying info.toml file
|
||||
#[derive(Deserialize)]
|
||||
pub struct Exercise {
|
||||
// Name of the exercise
|
||||
pub name: String,
|
||||
// The path to the file containing the exercise's source code
|
||||
pub path: PathBuf,
|
||||
// The mode of the exercise (Test, Compile, or Clippy)
|
||||
pub mode: Mode,
|
||||
// The hint text associated with the exercise
|
||||
pub hint: String,
|
||||
}
|
||||
|
||||
// An enum to track of the state of an Exercise.
|
||||
// An Exercise can be either Done or Pending
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum State {
|
||||
// The state of the exercise once it's been completed
|
||||
Done,
|
||||
// The state of the exercise while it's not completed yet
|
||||
Pending(Vec<ContextLine>),
|
||||
}
|
||||
|
||||
// The context information of a pending exercise
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct ContextLine {
|
||||
// The source code that is still pending completion
|
||||
pub line: String,
|
||||
// The line number of the source code still pending completion
|
||||
pub number: usize,
|
||||
// Whether or not this is important
|
||||
pub important: bool,
|
||||
}
|
||||
|
||||
// The result of compiling an exercise
|
||||
pub struct CompiledExercise<'a> {
|
||||
exercise: &'a Exercise,
|
||||
_handle: FileHandle,
|
||||
}
|
||||
|
||||
impl<'a> CompiledExercise<'a> {
|
||||
// Run the compiled exercise
|
||||
pub fn run(&self) -> Result<ExerciseOutput, ExerciseOutput> {
|
||||
self.exercise.run()
|
||||
}
|
||||
}
|
||||
|
||||
// A representation of an already executed binary
|
||||
#[derive(Debug)]
|
||||
pub struct ExerciseOutput {
|
||||
// The textual contents of the standard output of the binary
|
||||
pub stdout: String,
|
||||
// The textual contents of the standard error of the binary
|
||||
pub stderr: String,
|
||||
}
|
||||
|
||||
struct FileHandle;
|
||||
|
||||
impl Drop for FileHandle {
|
||||
fn drop(&mut self) {
|
||||
clean();
|
||||
}
|
||||
}
|
||||
|
||||
impl Exercise {
|
||||
pub fn compile(&self) -> Output {
|
||||
match self.mode {
|
||||
pub fn compile(&self) -> Result<CompiledExercise, ExerciseOutput> {
|
||||
let cmd = match self.mode {
|
||||
Mode::Compile => Command::new("rustc")
|
||||
.args(&[self.path.to_str().unwrap(), "-o", &temp_file()])
|
||||
.args(RUSTC_COLOR_ARGS)
|
||||
@@ -58,18 +115,80 @@ impl Exercise {
|
||||
.args(&["--test", self.path.to_str().unwrap(), "-o", &temp_file()])
|
||||
.args(RUSTC_COLOR_ARGS)
|
||||
.output(),
|
||||
Mode::Clippy => {
|
||||
let cargo_toml = format!(
|
||||
r#"[package]
|
||||
name = "{}"
|
||||
version = "0.0.1"
|
||||
edition = "2018"
|
||||
[[bin]]
|
||||
name = "{}"
|
||||
path = "{}.rs""#,
|
||||
self.name, self.name, self.name
|
||||
);
|
||||
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
|
||||
.expect("Failed to write 📎 Clippy 📎 Cargo.toml file.");
|
||||
// To support the ability to run the clipy exercises, build
|
||||
// an executable, in addition to running clippy. With a
|
||||
// compilation failure, this would silently fail. But we expect
|
||||
// clippy to reflect the same failure while compiling later.
|
||||
Command::new("rustc")
|
||||
.args(&[self.path.to_str().unwrap(), "-o", &temp_file()])
|
||||
.args(RUSTC_COLOR_ARGS)
|
||||
.output()
|
||||
.expect("Failed to compile!");
|
||||
// Due to an issue with Clippy, a cargo clean is required to catch all lints.
|
||||
// See https://github.com/rust-lang/rust-clippy/issues/2604
|
||||
// This is already fixed on Clippy's master branch. See this issue to track merging into Cargo:
|
||||
// https://github.com/rust-lang/rust-clippy/issues/3837
|
||||
Command::new("cargo")
|
||||
.args(&["clean", "--manifest-path", CLIPPY_CARGO_TOML_PATH])
|
||||
.args(RUSTC_COLOR_ARGS)
|
||||
.output()
|
||||
.expect("Failed to run 'cargo clean'");
|
||||
Command::new("cargo")
|
||||
.args(&["clippy", "--manifest-path", CLIPPY_CARGO_TOML_PATH])
|
||||
.args(RUSTC_COLOR_ARGS)
|
||||
.args(&["--", "-D", "warnings"])
|
||||
.output()
|
||||
}
|
||||
}
|
||||
.expect("Failed to run 'compile' command.");
|
||||
|
||||
if cmd.status.success() {
|
||||
Ok(CompiledExercise {
|
||||
exercise: &self,
|
||||
_handle: FileHandle,
|
||||
})
|
||||
} else {
|
||||
clean();
|
||||
Err(ExerciseOutput {
|
||||
stdout: String::from_utf8_lossy(&cmd.stdout).to_string(),
|
||||
stderr: String::from_utf8_lossy(&cmd.stderr).to_string(),
|
||||
})
|
||||
}
|
||||
.expect("Failed to run 'compile' command.")
|
||||
}
|
||||
|
||||
pub fn run(&self) -> Output {
|
||||
Command::new(&temp_file())
|
||||
fn run(&self) -> Result<ExerciseOutput, ExerciseOutput> {
|
||||
let arg = match self.mode {
|
||||
Mode::Test => "--show-output",
|
||||
_ => "",
|
||||
};
|
||||
let cmd = Command::new(&temp_file())
|
||||
.arg(arg)
|
||||
.output()
|
||||
.expect("Failed to run 'run' command")
|
||||
}
|
||||
.expect("Failed to run 'run' command");
|
||||
|
||||
pub fn clean(&self) {
|
||||
let _ignored = remove_file(&temp_file());
|
||||
let output = ExerciseOutput {
|
||||
stdout: String::from_utf8_lossy(&cmd.stdout).to_string(),
|
||||
stderr: String::from_utf8_lossy(&cmd.stderr).to_string(),
|
||||
};
|
||||
|
||||
if cmd.status.success() {
|
||||
Ok(output)
|
||||
} else {
|
||||
Err(output)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn state(&self) -> State {
|
||||
@@ -121,6 +240,11 @@ impl Display for Exercise {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clean() {
|
||||
let _ignored = remove_file(&temp_file());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
@@ -131,11 +255,12 @@ mod test {
|
||||
File::create(&temp_file()).unwrap();
|
||||
let exercise = Exercise {
|
||||
name: String::from("example"),
|
||||
path: PathBuf::from("example.rs"),
|
||||
mode: Mode::Test,
|
||||
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
||||
mode: Mode::Compile,
|
||||
hint: String::from(""),
|
||||
};
|
||||
exercise.clean();
|
||||
let compiled = exercise.compile().unwrap();
|
||||
drop(compiled);
|
||||
assert!(!Path::new(&temp_file()).exists());
|
||||
}
|
||||
|
||||
@@ -191,4 +316,16 @@ mod test {
|
||||
|
||||
assert_eq!(exercise.state(), State::Done);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exercise_with_output() {
|
||||
let exercise = Exercise {
|
||||
name: "exercise_with_output".into(),
|
||||
path: PathBuf::from("tests/fixture/success/testSuccess.rs"),
|
||||
mode: Mode::Test,
|
||||
hint: String::new(),
|
||||
};
|
||||
let out = exercise.compile().unwrap().run().unwrap();
|
||||
assert!(out.stdout.contains("THIS TEST TOO SHALL PASS"));
|
||||
}
|
||||
}
|
||||
|
||||
99
src/main.rs
99
src/main.rs
@@ -15,6 +15,9 @@ use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
#[macro_use]
|
||||
mod ui;
|
||||
|
||||
mod exercise;
|
||||
mod run;
|
||||
mod verify;
|
||||
@@ -22,10 +25,23 @@ mod verify;
|
||||
fn main() {
|
||||
let matches = App::new("rustlings")
|
||||
.version(crate_version!())
|
||||
.author("Olivia Hugger, Carol Nichols")
|
||||
.author("Marisa, Carol Nichols")
|
||||
.about("Rustlings is a collection of small exercises to get you used to writing and reading Rust code")
|
||||
.subcommand(SubCommand::with_name("verify").alias("v").about("Verifies all exercises according to the recommended order"))
|
||||
.subcommand(SubCommand::with_name("watch").alias("w").about("Reruns `verify` when files were edited"))
|
||||
.arg(
|
||||
Arg::with_name("nocapture")
|
||||
.long("nocapture")
|
||||
.help("Show outputs from the test exercises")
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("verify")
|
||||
.alias("v")
|
||||
.about("Verifies all exercises according to the recommended order")
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("watch")
|
||||
.alias("w")
|
||||
.about("Reruns `verify` when files were edited")
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("run")
|
||||
.alias("r")
|
||||
@@ -38,9 +54,14 @@ fn main() {
|
||||
.about("Returns a hint for the current exercise")
|
||||
.arg(Arg::with_name("name").required(true).index(1)),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("list")
|
||||
.alias("l")
|
||||
.about("Lists the exercises available in rustlings")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if None == matches.subcommand_name() {
|
||||
if matches.subcommand_name().is_none() {
|
||||
println!();
|
||||
println!(r#" welcome to... "#);
|
||||
println!(r#" _ _ _ "#);
|
||||
@@ -70,7 +91,11 @@ fn main() {
|
||||
|
||||
let toml_str = &fs::read_to_string("info.toml").unwrap();
|
||||
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
|
||||
let verbose = matches.is_present("nocapture");
|
||||
|
||||
if matches.subcommand_matches("list").is_some() {
|
||||
exercises.iter().for_each(|e| println!("{}", e.name));
|
||||
}
|
||||
if let Some(ref matches) = matches.subcommand_matches("run") {
|
||||
let name = matches.value_of("name").unwrap();
|
||||
|
||||
@@ -81,7 +106,7 @@ fn main() {
|
||||
std::process::exit(1)
|
||||
});
|
||||
|
||||
run(&exercise).unwrap_or_else(|_| std::process::exit(1));
|
||||
run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
if let Some(ref matches) = matches.subcommand_matches("hint") {
|
||||
@@ -99,25 +124,46 @@ fn main() {
|
||||
}
|
||||
|
||||
if matches.subcommand_matches("verify").is_some() {
|
||||
verify(&exercises).unwrap_or_else(|_| std::process::exit(1));
|
||||
verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
if matches.subcommand_matches("watch").is_some() {
|
||||
if watch(&exercises).is_ok() {
|
||||
println!(
|
||||
"{emoji} All exercises completed! {emoji}",
|
||||
emoji = Emoji("🎉", "★")
|
||||
);
|
||||
println!("");
|
||||
println!("We hope you enjoyed learning about the various aspects of Rust!");
|
||||
println!(
|
||||
"If you noticed any issues, please don't hesitate to report them to our repo."
|
||||
);
|
||||
println!("You can also contribute your own exercises to help the greater community!");
|
||||
println!("");
|
||||
println!("Before reporting an issue or contributing, please read our guidelines:");
|
||||
println!("https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md");
|
||||
if let Err(e) = watch(&exercises, verbose) {
|
||||
println!("Error: Could not watch your progess. 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);
|
||||
}
|
||||
println!(
|
||||
"{emoji} All exercises completed! {emoji}",
|
||||
emoji = Emoji("🎉", "★")
|
||||
);
|
||||
println!();
|
||||
println!("+----------------------------------------------------+");
|
||||
println!("| You made it to the Fe-nish line! |");
|
||||
println!("+-------------------------- ------------------------+");
|
||||
println!(" \\/ ");
|
||||
println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ ");
|
||||
println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ ");
|
||||
println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ ");
|
||||
println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ ");
|
||||
println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ ");
|
||||
println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ ");
|
||||
println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ ");
|
||||
println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ ");
|
||||
println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ");
|
||||
println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ ");
|
||||
println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ ");
|
||||
println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ");
|
||||
println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ ");
|
||||
println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ");
|
||||
println!(" ▒▒ ▒▒ ▒▒ ▒▒ ");
|
||||
println!();
|
||||
println!("We hope you enjoyed learning about the various aspects of Rust!");
|
||||
println!("If you noticed any issues, please don't hesitate to report them to our repo.");
|
||||
println!("You can also contribute your own exercises to help the greater community!");
|
||||
println!();
|
||||
println!("Before reporting an issue or contributing, please read our guidelines:");
|
||||
println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md");
|
||||
}
|
||||
|
||||
if matches.subcommand_name().is_none() {
|
||||
@@ -128,15 +174,18 @@ fn main() {
|
||||
|
||||
fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) {
|
||||
let failed_exercise_hint = Arc::clone(failed_exercise_hint);
|
||||
println!("Type 'hint' to get help");
|
||||
println!("Type 'hint' to get help or 'clear' to clear the screen");
|
||||
thread::spawn(move || loop {
|
||||
let mut input = String::new();
|
||||
match io::stdin().read_line(&mut input) {
|
||||
Ok(_) => {
|
||||
if input.trim().eq("hint") {
|
||||
let input = input.trim();
|
||||
if input.eq("hint") {
|
||||
if let Some(hint) = &*failed_exercise_hint.lock().unwrap() {
|
||||
println!("{}", hint);
|
||||
}
|
||||
} else if input.eq("clear") {
|
||||
println!("\x1B[2J\x1B[1;1H");
|
||||
} else {
|
||||
println!("unknown command: {}", input);
|
||||
}
|
||||
@@ -146,7 +195,7 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) {
|
||||
});
|
||||
}
|
||||
|
||||
fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||
fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {
|
||||
/* Clears the terminal with an ANSI escape code.
|
||||
Works in UNIX and newer Windows terminals. */
|
||||
fn clear_screen() {
|
||||
@@ -161,7 +210,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||
clear_screen();
|
||||
|
||||
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
|
||||
let failed_exercise_hint = match verify(exercises.iter()) {
|
||||
let failed_exercise_hint = match verify(exercises.iter(), verbose) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
|
||||
};
|
||||
@@ -176,7 +225,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||
.iter()
|
||||
.skip_while(|e| !filepath.ends_with(&e.path));
|
||||
clear_screen();
|
||||
match verify(pending_exercises) {
|
||||
match verify(pending_exercises, verbose) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(exercise) => {
|
||||
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
|
||||
|
||||
66
src/run.rs
66
src/run.rs
@@ -1,52 +1,58 @@
|
||||
use crate::exercise::{Exercise, Mode};
|
||||
use crate::verify::test;
|
||||
use console::{style, Emoji};
|
||||
use indicatif::ProgressBar;
|
||||
|
||||
pub fn run(exercise: &Exercise) -> Result<(), ()> {
|
||||
// Invoke the rust compiler on the path of the given exercise,
|
||||
// and run the ensuing binary.
|
||||
// The verbose argument helps determine whether or not to show
|
||||
// the output from the test harnesses (if the mode of the exercise is test)
|
||||
pub fn run(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
||||
match exercise.mode {
|
||||
Mode::Test => test(exercise)?,
|
||||
Mode::Test => test(exercise, verbose)?,
|
||||
Mode::Compile => compile_and_run(exercise)?,
|
||||
Mode::Clippy => compile_and_run(exercise)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn compile_and_run(exercise: &Exercise) -> Result<(), ()> {
|
||||
// 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
|
||||
fn compile_and_run(exercise: &Exercise) -> Result<(), ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {}...", exercise).as_str());
|
||||
progress_bar.enable_steady_tick(100);
|
||||
|
||||
let compilecmd = exercise.compile();
|
||||
let compilation_result = exercise.compile();
|
||||
let compilation = match compilation_result {
|
||||
Ok(compilation) => compilation,
|
||||
Err(output) => {
|
||||
progress_bar.finish_and_clear();
|
||||
warn!(
|
||||
"Compilation of {} failed!, Compiler error message:\n",
|
||||
exercise
|
||||
);
|
||||
println!("{}", output.stderr);
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
|
||||
progress_bar.set_message(format!("Running {}...", exercise).as_str());
|
||||
if compilecmd.status.success() {
|
||||
let runcmd = exercise.run();
|
||||
progress_bar.finish_and_clear();
|
||||
let result = compilation.run();
|
||||
progress_bar.finish_and_clear();
|
||||
|
||||
if runcmd.status.success() {
|
||||
println!("{}", String::from_utf8_lossy(&runcmd.stdout));
|
||||
let formatstr = format!("{} Successfully ran {}", Emoji("✅", "✓"), exercise);
|
||||
println!("{}", style(formatstr).green());
|
||||
exercise.clean();
|
||||
match result {
|
||||
Ok(output) => {
|
||||
println!("{}", output.stdout);
|
||||
success!("Successfully ran {}", exercise);
|
||||
Ok(())
|
||||
} else {
|
||||
println!("{}", String::from_utf8_lossy(&runcmd.stdout));
|
||||
println!("{}", String::from_utf8_lossy(&runcmd.stderr));
|
||||
}
|
||||
Err(output) => {
|
||||
println!("{}", output.stdout);
|
||||
println!("{}", output.stderr);
|
||||
|
||||
let formatstr = format!("{} Ran {} with errors", Emoji("⚠️ ", "!"), exercise);
|
||||
println!("{}", style(formatstr).red());
|
||||
exercise.clean();
|
||||
warn!("Ran {} with errors", exercise);
|
||||
Err(())
|
||||
}
|
||||
} else {
|
||||
progress_bar.finish_and_clear();
|
||||
let formatstr = format!(
|
||||
"{} Compilation of {} failed! Compiler error message:\n",
|
||||
Emoji("⚠️ ", "!"),
|
||||
exercise
|
||||
);
|
||||
println!("{}", style(formatstr).red());
|
||||
println!("{}", String::from_utf8_lossy(&compilecmd.stderr));
|
||||
exercise.clean();
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
23
src/ui.rs
Normal file
23
src/ui.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
macro_rules! warn {
|
||||
($fmt:literal, $ex:expr) => {{
|
||||
use console::{style, Emoji};
|
||||
let formatstr = format!($fmt, $ex);
|
||||
println!(
|
||||
"{} {}",
|
||||
style(Emoji("⚠️ ", "!")).red(),
|
||||
style(formatstr).red()
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! success {
|
||||
($fmt:literal, $ex:expr) => {{
|
||||
use console::{style, Emoji};
|
||||
let formatstr = format!($fmt, $ex);
|
||||
println!(
|
||||
"{} {}",
|
||||
style(Emoji("✅", "✓")).green(),
|
||||
style(formatstr).green()
|
||||
);
|
||||
}};
|
||||
}
|
||||
177
src/verify.rs
177
src/verify.rs
@@ -1,12 +1,21 @@
|
||||
use crate::exercise::{Exercise, Mode, State};
|
||||
use console::{style, Emoji};
|
||||
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
||||
use console::style;
|
||||
use indicatif::ProgressBar;
|
||||
|
||||
pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<(), &'a Exercise> {
|
||||
// Verify that the provided container of Exercise objects
|
||||
// can be compiled and run without any failures.
|
||||
// Any such failures will be reported to the end user.
|
||||
// If the Exercise being verified is a test, the verbose boolean
|
||||
// determines whether or not the test harness outputs are displayed.
|
||||
pub fn verify<'a>(
|
||||
start_at: impl IntoIterator<Item = &'a Exercise>,
|
||||
verbose: bool,
|
||||
) -> Result<(), &'a Exercise> {
|
||||
for exercise in start_at {
|
||||
let compile_result = match exercise.mode {
|
||||
Mode::Test => compile_and_test_interactively(&exercise),
|
||||
Mode::Compile => compile_only(&exercise),
|
||||
Mode::Test => compile_and_test(&exercise, RunMode::Interactive, verbose),
|
||||
Mode::Compile => compile_and_run_interactively(&exercise),
|
||||
Mode::Clippy => compile_only(&exercise),
|
||||
};
|
||||
if !compile_result.unwrap_or(false) {
|
||||
return Err(exercise);
|
||||
@@ -15,82 +24,114 @@ pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn test(exercise: &Exercise) -> Result<(), ()> {
|
||||
compile_and_test(exercise, true)?;
|
||||
enum RunMode {
|
||||
Interactive,
|
||||
NonInteractive,
|
||||
}
|
||||
|
||||
// Compile and run the resulting test harness of the given Exercise
|
||||
pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
||||
compile_and_test(exercise, RunMode::NonInteractive, verbose)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Invoke the rust compiler without running the resulting binary
|
||||
fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {}...", exercise).as_str());
|
||||
progress_bar.enable_steady_tick(100);
|
||||
let compile_output = exercise.compile();
|
||||
|
||||
let _ = compile(&exercise, &progress_bar)?;
|
||||
progress_bar.finish_and_clear();
|
||||
if compile_output.status.success() {
|
||||
let formatstr = format!("{} Successfully compiled {}!", Emoji("✅", "✓"), exercise);
|
||||
println!("{}", style(formatstr).green());
|
||||
exercise.clean();
|
||||
Ok(prompt_for_completion(&exercise))
|
||||
} else {
|
||||
let formatstr = format!(
|
||||
"{} Compilation of {} failed! Compiler error message:\n",
|
||||
Emoji("⚠️ ", "!"),
|
||||
exercise
|
||||
);
|
||||
println!("{}", style(formatstr).red());
|
||||
println!("{}", String::from_utf8_lossy(&compile_output.stderr));
|
||||
exercise.clean();
|
||||
Err(())
|
||||
}
|
||||
|
||||
success!("Successfully compiled {}!", exercise);
|
||||
Ok(prompt_for_completion(&exercise, None))
|
||||
}
|
||||
|
||||
fn compile_and_test_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
||||
compile_and_test(exercise, false)
|
||||
// Compile the given Exercise and run the resulting binary in an interactive mode
|
||||
fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {}...", exercise).as_str());
|
||||
progress_bar.enable_steady_tick(100);
|
||||
|
||||
let compilation = compile(&exercise, &progress_bar)?;
|
||||
|
||||
progress_bar.set_message(format!("Running {}...", exercise).as_str());
|
||||
let result = compilation.run();
|
||||
progress_bar.finish_and_clear();
|
||||
|
||||
let output = match result {
|
||||
Ok(output) => output,
|
||||
Err(output) => {
|
||||
warn!("Ran {} with errors", exercise);
|
||||
println!("{}", output.stdout);
|
||||
println!("{}", output.stderr);
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
|
||||
success!("Successfully ran {}!", exercise);
|
||||
|
||||
Ok(prompt_for_completion(&exercise, Some(output.stdout)))
|
||||
}
|
||||
|
||||
fn compile_and_test(exercise: &Exercise, skip_prompt: bool) -> Result<bool, ()> {
|
||||
// Compile the given Exercise as a test harness and display
|
||||
// the output if verbose is set to true
|
||||
fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Testing {}...", exercise).as_str());
|
||||
progress_bar.enable_steady_tick(100);
|
||||
|
||||
let compile_output = exercise.compile();
|
||||
if compile_output.status.success() {
|
||||
progress_bar.set_message(format!("Running {}...", exercise).as_str());
|
||||
let compilation = compile(exercise, &progress_bar)?;
|
||||
let result = compilation.run();
|
||||
progress_bar.finish_and_clear();
|
||||
|
||||
let runcmd = exercise.run();
|
||||
progress_bar.finish_and_clear();
|
||||
|
||||
if runcmd.status.success() {
|
||||
let formatstr = format!("{} Successfully tested {}!", Emoji("✅", "✓"), exercise);
|
||||
println!("{}", style(formatstr).green());
|
||||
exercise.clean();
|
||||
Ok(skip_prompt || prompt_for_completion(exercise))
|
||||
} else {
|
||||
let formatstr = format!(
|
||||
"{} Testing of {} failed! Please try again. Here's the output:",
|
||||
Emoji("⚠️ ", "!"),
|
||||
match result {
|
||||
Ok(output) => {
|
||||
if verbose {
|
||||
println!("{}", output.stdout);
|
||||
}
|
||||
success!("Successfully tested {}", &exercise);
|
||||
if let RunMode::Interactive = run_mode {
|
||||
Ok(prompt_for_completion(&exercise, None))
|
||||
} else {
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
Err(output) => {
|
||||
warn!(
|
||||
"Testing of {} failed! Please try again. Here's the output:",
|
||||
exercise
|
||||
);
|
||||
println!("{}", style(formatstr).red());
|
||||
println!("{}", String::from_utf8_lossy(&runcmd.stdout));
|
||||
exercise.clean();
|
||||
println!("{}", output.stdout);
|
||||
Err(())
|
||||
}
|
||||
} else {
|
||||
progress_bar.finish_and_clear();
|
||||
let formatstr = format!(
|
||||
"{} Compiling of {} failed! Please try again. Here's the output:",
|
||||
Emoji("⚠️ ", "!"),
|
||||
exercise
|
||||
);
|
||||
println!("{}", style(formatstr).red());
|
||||
println!("{}", String::from_utf8_lossy(&compile_output.stderr));
|
||||
exercise.clean();
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_for_completion(exercise: &Exercise) -> bool {
|
||||
// Compile the given Exercise and return an object with information
|
||||
// about the state of the compilation
|
||||
fn compile<'a, 'b>(
|
||||
exercise: &'a Exercise,
|
||||
progress_bar: &'b ProgressBar,
|
||||
) -> Result<CompiledExercise<'a>, ()> {
|
||||
let compilation_result = exercise.compile();
|
||||
|
||||
match compilation_result {
|
||||
Ok(compilation) => Ok(compilation),
|
||||
Err(output) => {
|
||||
progress_bar.finish_and_clear();
|
||||
warn!(
|
||||
"Compiling of {} failed! Please try again. Here's the output:",
|
||||
exercise
|
||||
);
|
||||
println!("{}", output.stderr);
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) -> bool {
|
||||
let context = match exercise.state() {
|
||||
State::Done => return true,
|
||||
State::Pending(context) => context,
|
||||
@@ -99,22 +140,32 @@ fn prompt_for_completion(exercise: &Exercise) -> bool {
|
||||
let success_msg = match exercise.mode {
|
||||
Mode::Compile => "The code is compiling!",
|
||||
Mode::Test => "The code is compiling, and the tests pass!",
|
||||
Mode::Clippy => "The code is compiling, and 📎 Clippy 📎 is happy!",
|
||||
};
|
||||
|
||||
println!("");
|
||||
println!();
|
||||
println!("🎉 🎉 {} 🎉 🎉", success_msg);
|
||||
println!("");
|
||||
println!();
|
||||
|
||||
if let Some(output) = prompt_output {
|
||||
println!("Output:");
|
||||
println!("{}", separator());
|
||||
println!("{}", output);
|
||||
println!("{}", separator());
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("You can keep working on this exercise,");
|
||||
println!(
|
||||
"or jump into the next one by removing the {} comment:",
|
||||
style("`I AM NOT DONE`").bold()
|
||||
);
|
||||
println!("");
|
||||
println!();
|
||||
for context_line in context {
|
||||
let formatted_line = if context_line.important {
|
||||
format!("{}", style(context_line.line).bold())
|
||||
} else {
|
||||
format!("{}", context_line.line)
|
||||
context_line.line.to_string()
|
||||
};
|
||||
|
||||
println!(
|
||||
@@ -127,3 +178,7 @@ fn prompt_for_completion(exercise: &Exercise) -> bool {
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn separator() -> console::StyledObject<&'static str> {
|
||||
style("====================").bold()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#[test]
|
||||
fn passing() {
|
||||
println!("THIS TEST TOO SHALL PASS");
|
||||
assert!(true);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ fn verify_all_success() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_all_failure() {
|
||||
fn verify_fails_if_some_fails() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.arg("v")
|
||||
@@ -159,3 +159,25 @@ fn run_test_exercise_does_not_prompt() {
|
||||
.code(0)
|
||||
.stdout(predicates::str::contains("I AM NOT DONE").not());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_test_success_with_output() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(&["--nocapture", "r", "testSuccess"])
|
||||
.current_dir("tests/fixture/success/")
|
||||
.assert()
|
||||
.code(0)
|
||||
.stdout(predicates::str::contains("THIS TEST TOO SHALL PAS"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_test_success_without_output() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(&["r", "testSuccess"])
|
||||
.current_dir("tests/fixture/success/")
|
||||
.assert()
|
||||
.code(0)
|
||||
.stdout(predicates::str::contains("THIS TEST TOO SHALL PAS").not());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user