Compare commits
333 commits
Author | SHA1 | Date | |
---|---|---|---|
|
84bb490545 | ||
|
aa2ce0ee19 | ||
|
f1bf7b5735 | ||
|
f81fe2b60c | ||
|
5b989095cd | ||
|
cdd8e19716 | ||
|
91d86a1de9 | ||
|
6a10f900b4 | ||
|
9b9a89c79a | ||
|
123e6426d1 | ||
|
427ec6b2e4 | ||
|
03dcb582e6 | ||
|
1043a06124 | ||
|
d20e413a68 | ||
|
9bf4c5e8df | ||
|
633303d4b8 | ||
|
a4a1098766 | ||
|
0bd459dcac | ||
|
3b4514b686 | ||
|
2e05606edc | ||
|
c8c1b87a01 | ||
|
34ea029df8 | ||
|
3a4433d5a2 | ||
|
de6c45ad24 | ||
|
fadade8592 | ||
|
d91044f3a2 | ||
|
a3ea37b76e | ||
|
ec63cadadb | ||
|
84d8305730 | ||
|
73777980f1 | ||
|
75788b1148 | ||
|
dd9b2ddc89 | ||
|
b7ddd09fab | ||
|
48ffcbd2c4 | ||
|
68d3ac567c | ||
|
50ab289da6 | ||
|
4e079fdd08 | ||
|
91fc9e3118 | ||
|
a2f0401c4c | ||
|
1b85828548 | ||
|
4c46e5e1a3 | ||
|
4da9e7ee29 | ||
|
72e615aa7a | ||
|
cd02abc481 | ||
|
399ab328d8 | ||
|
809ec2ce01 | ||
|
11d2cf0d60 | ||
|
dbb2624403 | ||
|
4d4fa77459 | ||
|
3145794084 | ||
|
d9b69bd1a0 | ||
|
7cd635fa84 | ||
|
ce40e201f0 | ||
|
404f3ef465 | ||
|
e1be594fdd | ||
|
9569c9a9e7 | ||
|
91530f5716 | ||
|
650b1dee54 | ||
|
6b6dc9dd48 | ||
|
3a9ec4192d | ||
|
4f7dbbd2c3 | ||
|
8c37db1a23 | ||
|
c6b7ad8878 | ||
|
84461c20cb | ||
|
3cddda56fc | ||
|
37f3069a67 | ||
|
2b2fbe918e | ||
|
cf42ddc449 | ||
|
eefa656232 | ||
|
249ad44cc0 | ||
|
54804e344d | ||
|
1c334de6fd | ||
|
f253103a31 | ||
|
1120db57a6 | ||
|
afa661cff4 | ||
|
347f30bd86 | ||
|
127773f3f5 | ||
|
8d0490bd70 | ||
|
293dfb35d5 | ||
|
81be404487 | ||
|
6177b6e126 | ||
|
79cc657917 | ||
|
7928122fce | ||
|
9c88ea9126 | ||
|
2b766ef9f9 | ||
|
bd3d9ac9d5 | ||
|
aa0db8379c | ||
|
eadd41a9ec | ||
|
fab2eb9833 | ||
|
6bd791f2f4 | ||
|
ec5f80dce1 | ||
|
65cdc856ae | ||
|
472f61485e | ||
|
b4de659438 | ||
|
a37a8818c8 | ||
|
bdf01aa174 | ||
|
a941c69f09 | ||
|
72aaa15e6a | ||
|
3a06de71a8 | ||
|
5e2b39a5c1 | ||
|
63c942233e | ||
|
2612edc133 | ||
|
e2ce9f42b5 | ||
|
1c6f7e4b7b | ||
|
e2c41903ad | ||
|
bd48544e25 | ||
|
c0e3daacaf | ||
|
f2ad3a6a0b | ||
|
caf921a01f | ||
|
b790bafc02 | ||
|
ad3cd54cce | ||
|
1a6a725f88 | ||
|
1ad20d94ff | ||
|
995c6f0fb1 | ||
|
c3e7b83178 | ||
|
2e93a588e0 | ||
|
9aeca3f97e | ||
|
2193fff4bb | ||
|
aec2c65c63 | ||
|
a6509cc4d5 | ||
|
a02b279750 | ||
|
ece841f5ce | ||
|
2a6e4dc8a6 | ||
|
c163011cc0 | ||
|
b350945a16 | ||
|
1ef368a69d | ||
|
8dc587b01a | ||
|
550c4293ed | ||
|
3df094713f | ||
|
01e7f27aa6 | ||
|
8d62a99637 | ||
|
ab9995e76e | ||
|
bef39b1259 | ||
|
0d894e6ff7 | ||
|
be9510539e | ||
|
3bce2ef8d6 | ||
|
aa9a943ddf | ||
|
ebdb66c7bf | ||
|
9f3e8c2dde | ||
|
96c56ab08a | ||
|
04dbf03ace | ||
|
05a753fe63 | ||
|
815edb7003 | ||
|
5157f56875 | ||
|
3f5abca215 | ||
|
833df0b8b3 | ||
|
6742860ea5 | ||
|
797e6d45c0 | ||
|
320de0d921 | ||
|
5eed505d74 | ||
|
91ee27f22b | ||
|
5f7c89f85d | ||
|
c6712dfccd | ||
|
baf4ba175b | ||
|
b29ea17ea9 | ||
|
ab57c26cf9 | ||
|
98e5e8835e | ||
|
f5158ece1a | ||
|
d65b4a9a93 | ||
|
8404947bc0 | ||
|
2e84f34cf3 | ||
|
726805f064 | ||
|
b4a4138559 | ||
|
f1d2b3a39a | ||
|
1f9d006858 | ||
|
cc266d7d80 | ||
|
fff72afe2e | ||
|
c1abd13b5c | ||
|
75802c14b2 | ||
|
cddc1e86e7 | ||
|
24ea42ce61 | ||
|
6102e612fa | ||
|
52bde71166 | ||
|
15a79cfe9c | ||
|
15e71535f3 | ||
|
9f988bfe29 | ||
|
e8d1baa4b5 | ||
|
8bbe4ff138 | ||
|
0b9220c1fc | ||
|
0d65753fdb | ||
|
4f1374a6e7 | ||
|
5a0521e92c | ||
|
fea86c29d6 | ||
|
9c4614f7e6 | ||
|
c24a78ae94 | ||
|
621816fb56 | ||
|
cfae54d361 | ||
|
7857b0a689 | ||
|
10965920fb | ||
|
d2e7ecabd8 | ||
|
5772589dc3 | ||
|
6df08b411b | ||
|
c355ac6593 | ||
|
e9b42bbc2a | ||
|
1283aa3bd8 | ||
|
ff6cba7205 | ||
|
d0107f7921 | ||
|
644c49f1e0 | ||
|
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 |
.all-contributorsrc.gitignore.gitpod.yml.replitCHANGELOG.mdCONTRIBUTING.mdCargo.lockCargo.tomlREADME.mdbuildkite.ymldefault_out.txt
exercises
README.md
info.tomlinstall.ps1install.shclippy
collections
conversions
enums
error_handling
functions
generics
if
macros
modules
move_semantics
option
primitive_types
README.mdprimitive_types1.rsprimitive_types2.rsprimitive_types3.rsprimitive_types4.rsprimitive_types5.rsprimitive_types6.rs
quiz1.rsquiz2.rsquiz3.rsstandard_library_types
strings
structs
tests
threads
traits
variables
src
|
@ -454,11 +454,468 @@
|
|||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "wsh",
|
||||
"name": "Will Hayworth",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/181174?v=4",
|
||||
"profile": "http://willhayworth.com",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "chrizel",
|
||||
"name": "Christian Zeller",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/20802?v=4",
|
||||
"profile": "https://github.com/chrizel",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "jfchevrette",
|
||||
"name": "Jean-Francois Chevrette",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/3001?v=4",
|
||||
"profile": "https://github.com/jfchevrette",
|
||||
"contributions": [
|
||||
"content",
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "jbaber",
|
||||
"name": "John Baber-Lucero",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1908117?v=4",
|
||||
"profile": "https://github.com/jbaber",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "tal-zvon",
|
||||
"name": "Tal",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/3195851?v=4",
|
||||
"profile": "https://github.com/tal-zvon",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "apogeeoak",
|
||||
"name": "apogeeoak",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/59737221?v=4",
|
||||
"profile": "https://github.com/apogeeoak",
|
||||
"contributions": [
|
||||
"content",
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Crell",
|
||||
"name": "Larry Garfield",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/254863?v=4",
|
||||
"profile": "http://www.garfieldtech.com/",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "circumspect",
|
||||
"name": "circumspect",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/40770208?v=4",
|
||||
"profile": "https://github.com/circumspect",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "cjwyett",
|
||||
"name": "Cyrus Wyett",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/34195737?v=4",
|
||||
"profile": "https://github.com/cjwyett",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "cadolphs",
|
||||
"name": "cadolphs",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/13894820?v=4",
|
||||
"profile": "https://github.com/cadolphs",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "hpwxf",
|
||||
"name": "Pascal H.",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/26146722?v=4",
|
||||
"profile": "https://www.haveneer.com",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "chapeupreto",
|
||||
"name": "Rod Elias",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/834048?v=4",
|
||||
"profile": "https://twitter.com/chapeupreto",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "blerchy",
|
||||
"name": "Matt Lebl",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/2555355?v=4",
|
||||
"profile": "https://github.com/blerchy",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "flakolefluk",
|
||||
"name": "Ignacio Le Fluk",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/11986564?v=4",
|
||||
"profile": "http://flakolefluk.dev",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "tlyu",
|
||||
"name": "Taylor Yu",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/431873?v=4",
|
||||
"profile": "https://github.com/tlyu",
|
||||
"contributions": [
|
||||
"code",
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Zerotask",
|
||||
"name": "Patrick Hintermayer",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/20150243?v=4",
|
||||
"profile": "https://zerotask.github.io",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "arthas168",
|
||||
"name": "Pete Pavlovski",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/32264020?v=4",
|
||||
"profile": "https://petkopavlovski.com/",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "k12ish",
|
||||
"name": "k12ish",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/45272873?v=4",
|
||||
"profile": "https://github.com/k12ish",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "hongshaoyang",
|
||||
"name": "Shao Yang Hong",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/19281800?v=4",
|
||||
"profile": "https://github.com/hongshaoyang",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "bmacer",
|
||||
"name": "Brandon Macer",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/13931806?v=4",
|
||||
"profile": "https://github.com/bmacer",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "stoiandan",
|
||||
"name": "Stoian Dan",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/10388612?v=4",
|
||||
"profile": "https://github.com/stoiandan",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "PiDelport",
|
||||
"name": "Pi Delport",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/630271?v=4",
|
||||
"profile": "https://about.me/pjdelport",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "sateeshkumarb",
|
||||
"name": "Sateesh ",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/429263?v=4",
|
||||
"profile": "https://github.com/sateeshkumarb",
|
||||
"contributions": [
|
||||
"code",
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "kayuapi",
|
||||
"name": "ZC",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/10304328?v=4",
|
||||
"profile": "https://github.com/kayuapi",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "hyperparabolic",
|
||||
"name": "hyperparabolic",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/12348474?v=4",
|
||||
"profile": "https://github.com/hyperparabolic",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "kolbma",
|
||||
"name": "arlecchino",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/5228369?v=4",
|
||||
"profile": "https://www.net4visions.at",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "jazzplato",
|
||||
"name": "Richthofen",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7576730?v=4",
|
||||
"profile": "https://richthofen.io/",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "cseltol",
|
||||
"name": "Ivan Nerazumov",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/64264529?v=4",
|
||||
"profile": "https://github.com/cseltol",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 8,
|
||||
"projectName": "rustlings",
|
||||
"projectOwner": "fmoko",
|
||||
"projectOwner": "rust-lang",
|
||||
"repoType": "github",
|
||||
"repoHost": "https://github.com",
|
||||
"skipCi": true
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ target/
|
|||
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"
|
120
CHANGELOG.md
120
CHANGELOG.md
|
@ -1,10 +1,122 @@
|
|||
<a name="4.4.0"></a>
|
||||
## 4.4.0 (2021-04-24)
|
||||
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* Fix spelling error in main.rs ([91ee27f2](https://github.com/rust-lang/rustlings/commit/91ee27f22bd3797a9db57e5fd430801c170c5db8))
|
||||
* typo in default out text ([644c49f1](https://github.com/rust-lang/rustlings/commit/644c49f1e04cbb24e95872b3a52b07d692ae3bc8))
|
||||
* **collections:** Naming exercises for vectors and hashmap ([bef39b12](https://github.com/rust-lang/rustlings/commit/bef39b125961310b34b34871e480a82e82af4678))
|
||||
* **from_str:**
|
||||
* Correct typos ([5f7c89f8](https://github.com/rust-lang/rustlings/commit/5f7c89f85db1f33da01911eaa479c3a2d4721678))
|
||||
* test for error instead of unwrap/should_panic ([15e71535](https://github.com/rust-lang/rustlings/commit/15e71535f37cfaed36e22eb778728d186e2104ab))
|
||||
* use trait objects for from_str ([c3e7b831](https://github.com/rust-lang/rustlings/commit/c3e7b831786c9172ed8bd5d150f3c432f242fba9))
|
||||
* **functions3:** improve function argument type (#687) ([a6509cc4](https://github.com/rust-lang/rustlings/commit/a6509cc4d545d8825f01ddf7ee37823b372154dd))
|
||||
* **hashmap2:** Update incorrect assertion (#660) ([72aaa15e](https://github.com/rust-lang/rustlings/commit/72aaa15e6ab4b72b3422f1c6356396e20a2a2bb8))
|
||||
* **info:** Fix typo (#635) ([cddc1e86](https://github.com/rust-lang/rustlings/commit/cddc1e86e7ec744ee644cc774a4887b1a0ded3e8))
|
||||
* **iterators2:** Moved errors out of tests. ([baf4ba17](https://github.com/rust-lang/rustlings/commit/baf4ba175ba6eb92989e3dd54ecbec4bedc9a863), closes [#359](https://github.com/rust-lang/rustlings/issues/359))
|
||||
* **iterators3:** Enabled iterators3.rs to run without commented out tests. ([c6712dfc](https://github.com/rust-lang/rustlings/commit/c6712dfccd1a093e590ad22bbc4f49edc417dac0))
|
||||
* **main:** Let find_exercise work with borrows ([347f30bd](https://github.com/rust-lang/rustlings/commit/347f30bd867343c5ace1097e085a1f7e356553f7))
|
||||
* **move_semantics4:**
|
||||
* Remove redundant "instead" (#640) ([cc266d7d](https://github.com/rust-lang/rustlings/commit/cc266d7d80b91e79df3f61984f231b7f1587218e))
|
||||
* Small readbility improvement (#617) ([10965920](https://github.com/rust-lang/rustlings/commit/10965920fbdf8a1efc85bed869e55a1787006404))
|
||||
* **option2:** Rename uninformative variables (#675) ([b4de6594](https://github.com/rust-lang/rustlings/commit/b4de6594380636817d13c2677ec6f472a964cf43))
|
||||
* **quiz3:** Force an answer to Q2 (#672) ([0d894e6f](https://github.com/rust-lang/rustlings/commit/0d894e6ff739943901e1ae8c904582e5c2f843bd))
|
||||
* **structs:** Add 5.3 to structs/README (#652) ([6bd791f2](https://github.com/rust-lang/rustlings/commit/6bd791f2f44aa7f0ad926df767f6b1fa8f12a9a9))
|
||||
* **structs2:** correct grammar in hint (#663) ([ebdb66c7](https://github.com/rust-lang/rustlings/commit/ebdb66c7bfb6d687a14cc511a559a222e6fc5de4))
|
||||
* **structs3:**
|
||||
* reword heading comment (#664) ([9f3e8c2d](https://github.com/rust-lang/rustlings/commit/9f3e8c2dde645e5264c2d2200e68842b5f47bfa3))
|
||||
* add check to prevent naive implementation of is_international ([05a753fe](https://github.com/rust-lang/rustlings/commit/05a753fe6333d36dbee5f68c21dec04eacdc75df))
|
||||
* **threads1:** line number correction ([7857b0a6](https://github.com/rust-lang/rustlings/commit/7857b0a689b0847f48d8c14cbd1865e3b812d5ca))
|
||||
* **try_from_into:** use trait objects ([2e93a588](https://github.com/rust-lang/rustlings/commit/2e93a588e0abe8badb7eafafb9e7d073c2be5df8))
|
||||
|
||||
#### Features
|
||||
|
||||
* Replace clap with argh ([7928122f](https://github.com/rust-lang/rustlings/commit/7928122fcef9ca7834d988b1ec8ca0687478beeb))
|
||||
* Replace emojis when NO_EMOJI env variable present ([8d62a996](https://github.com/rust-lang/rustlings/commit/8d62a9963708dbecd9312e8bcc4b47049c72d155))
|
||||
* Added iterators5.rs exercise. ([b29ea17e](https://github.com/rust-lang/rustlings/commit/b29ea17ea94d1862114af2cf5ced0e09c197dc35))
|
||||
* **arc1:** Add more details to description and hint (#710) ([81be4044](https://github.com/rust-lang/rustlings/commit/81be40448777fa338ebced3b0bfc1b32d6370313))
|
||||
* **cli:** Improve the list command with options, and then some ([8bbe4ff1](https://github.com/rust-lang/rustlings/commit/8bbe4ff1385c5c169c90cd3ff9253f9a91daaf8e))
|
||||
* **list:**
|
||||
* updated progress percentage ([1c6f7e4b](https://github.com/rust-lang/rustlings/commit/1c6f7e4b7b9b3bd36f4da2bb2b69c549cc8bd913))
|
||||
* added progress info ([c0e3daac](https://github.com/rust-lang/rustlings/commit/c0e3daacaf6850811df5bc57fa43e0f249d5cfa4))
|
||||
|
||||
|
||||
|
||||
<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)
|
||||
* 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
|
||||
|
||||
|
@ -83,14 +195,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
|
||||
|
|
|
@ -26,12 +26,12 @@ isn't really that complicated since the bulk of the work is done by `rustc`.
|
|||
<a name="addex"></a>
|
||||
### Adding an exercise
|
||||
|
||||
First step is to add the exercise! Call it `exercises/yourTopic/yourTopicN.rs`, make sure to
|
||||
The first step is to add the exercise! Name the file `exercises/yourTopic/yourTopicN.rs`, make sure to
|
||||
put in some helpful links, and link to sections of the book in `exercises/yourTopic/README.md`.
|
||||
|
||||
Next you want to make sure it runs when using `rustlings`. All exercises are stored in `info.toml`, under the `exercises` array. They're ordered by the order they're ran when using `rustlings verify`.
|
||||
Next make sure it runs with `rustlings`. The exercise metadata is stored in `info.toml`, under the `exercises` array. The order of the `exercises` array determines the order the exercises are run by `rustlings verify`.
|
||||
|
||||
You want to make sure where in the file you add your exercise. If you're not sure, add it at the bottom and ask in your pull request. To add an exercise, edit the file like this:
|
||||
Add the metadata for your exercise in the correct order in the `exercises` array. If you are unsure of the correct ordering, add it at the bottom and ask in your pull request. The exercise metadata should contain the following:
|
||||
```diff
|
||||
...
|
||||
+ [[exercises]]
|
||||
|
|
835
Cargo.lock
generated
835
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,11 @@
|
|||
[package]
|
||||
name = "rustlings"
|
||||
version = "4.0.0"
|
||||
version = "4.4.0"
|
||||
authors = ["Marisa <mokou@posteo.de>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
clap = "2.32.0"
|
||||
argh = "0.1.4"
|
||||
indicatif = "0.10.3"
|
||||
console = "0.7.7"
|
||||
notify = "4.0.15"
|
||||
|
|
201
README.md
201
README.md
|
@ -1,200 +1,3 @@
|
|||

|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
# rustlings
|
||||
|
||||
# rustlings 🦀❤️ [](https://buildkite.com/mokou/rustlings)
|
||||
|
||||
Greetings and welcome to `rustlings`. This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!
|
||||
|
||||
_...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:
|
||||
|
||||
- [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
|
||||
|
||||
## Getting Started
|
||||
|
||||
_Note: If you're on MacOS, make sure you've installed Xcode and its developer tools by typing `xcode-select --install`._
|
||||
|
||||
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
|
||||
|
||||
Just run:
|
||||
|
||||
```bash
|
||||
curl -L https://git.io/rustlings | bash
|
||||
# Or if you want it to be installed to a different path:
|
||||
curl -L https://git.io/rustlings | bash -s mypath/
|
||||
```
|
||||
|
||||
This will install Rustlings and give you access to the `rustlings` command. Run it to get started!
|
||||
|
||||
## Windows
|
||||
|
||||
In PowerShell, set `ExecutionPolicy` to `RemoteSigned`:
|
||||
|
||||
```ps
|
||||
Set-ExecutionPolicy RemoteSigned
|
||||
```
|
||||
|
||||
Then, you can run:
|
||||
|
||||
```ps
|
||||
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.
|
||||
|
||||
## Manually
|
||||
|
||||
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/4.0.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest)
|
||||
cargo install --force --path .
|
||||
```
|
||||
|
||||
If there are installation errors, ensure that your toolchain is up to date. For the latest, run:
|
||||
```bash
|
||||
rustup update
|
||||
```
|
||||
|
||||
Then, same as above, run `rustlings` to get started.
|
||||
|
||||
## Doing exercises
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
rustlings watch
|
||||
```
|
||||
|
||||
This will try to verify the completion of every exercise in a predetermined order (what we think is best for newcomers). It will also rerun automatically every time you change a file in the `exercises/` directory. If you want to only run it once, you can use:
|
||||
|
||||
```bash
|
||||
rustlings verify
|
||||
```
|
||||
|
||||
This will do the same as watch, but it'll quit after running.
|
||||
|
||||
In case you want to go by your own order, or want to only verify a single exercise, you can run:
|
||||
|
||||
```bash
|
||||
rustlings run myExercise1
|
||||
```
|
||||
|
||||
In case you get stuck, you can run the following command to get a hint for your
|
||||
exercise:
|
||||
|
||||
``` bash
|
||||
rustlings hint myExercise1
|
||||
```
|
||||
|
||||
## Testing yourself
|
||||
|
||||
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`.
|
||||
|
||||
## Completion
|
||||
|
||||
Rustlings isn't done; there are a couple of sections that are very experimental and don't have proper documentation. These include:
|
||||
|
||||
- Errors (`exercises/errors/`)
|
||||
- Option (`exercises/option/`)
|
||||
- Result (`exercises/result/`)
|
||||
- Move Semantics (could still be improved, `exercises/move_semantics/`)
|
||||
|
||||
Additionally, we could use exercises on a couple of topics:
|
||||
|
||||
- Structs
|
||||
- Better ownership stuff
|
||||
- `impl`
|
||||
- ??? probably more
|
||||
|
||||
If you are interested in improving or adding new ones, please feel free to contribute! Read on for more information :)
|
||||
|
||||
## Contributing
|
||||
|
||||
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
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/fmoko/rustlings/commits?author=carols10cents" title="Code">💻</a> <a href="#content-carols10cents" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://twitter.com/QuietMisdreavus"><img src="https://avatars2.githubusercontent.com/u/5217170?v=4" width="100px;" alt=""/><br /><sub><b>QuietMisdreavus</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=QuietMisdreavus" title="Code">💻</a> <a href="#content-QuietMisdreavus" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/robertlugg"><img src="https://avatars0.githubusercontent.com/u/6054540?v=4" width="100px;" alt=""/><br /><sub><b>Robert M Lugg</b></sub></a><br /><a href="#content-robertlugg" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://hynek.me/about/"><img src="https://avatars3.githubusercontent.com/u/41240?v=4" width="100px;" alt=""/><br /><sub><b>Hynek Schlawack</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=hynek" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://spacekookie.de"><img src="https://avatars0.githubusercontent.com/u/7669898?v=4" width="100px;" alt=""/><br /><sub><b>Katharina Fey</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=spacekookie" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/lukabavdaz"><img src="https://avatars0.githubusercontent.com/u/9624558?v=4" width="100px;" alt=""/><br /><sub><b>lukabavdaz</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=lukabavdaz" title="Code">💻</a> <a href="#content-lukabavdaz" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://vestera.as"><img src="https://avatars2.githubusercontent.com/u/4187449?v=4" width="100px;" alt=""/><br /><sub><b>Erik Vesteraas</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=evestera" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/Delet0r"><img src="https://avatars1.githubusercontent.com/u/23195618?v=4" width="100px;" alt=""/><br /><sub><b>delet0r</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Delet0r" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="http://phinary.ca"><img src="https://avatars1.githubusercontent.com/u/10522375?v=4" width="100px;" alt=""/><br /><sub><b>Shaun Bennett</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=shaunbennett" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/abagshaw"><img src="https://avatars2.githubusercontent.com/u/8594541?v=4" width="100px;" alt=""/><br /><sub><b>Andrew Bagshaw</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=abagshaw" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://ai6ua.net/"><img src="https://avatars2.githubusercontent.com/u/175578?v=4" width="100px;" alt=""/><br /><sub><b>Kyle Isom</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=kisom" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/ColinPitrat"><img src="https://avatars3.githubusercontent.com/u/1541863?v=4" width="100px;" alt=""/><br /><sub><b>Colin Pitrat</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=ColinPitrat" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://zacanger.com"><img src="https://avatars3.githubusercontent.com/u/12520493?v=4" width="100px;" alt=""/><br /><sub><b>Zac Anger</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=zacanger" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/mgeier"><img src="https://avatars1.githubusercontent.com/u/705404?v=4" width="100px;" alt=""/><br /><sub><b>Matthias Geier</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=mgeier" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/cjpearce"><img src="https://avatars1.githubusercontent.com/u/3453268?v=4" width="100px;" alt=""/><br /><sub><b>Chris Pearce</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=cjpearce" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://yvan-sraka.github.io"><img src="https://avatars2.githubusercontent.com/u/705213?v=4" width="100px;" alt=""/><br /><sub><b>Yvan Sraka</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=yvan-sraka" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/dendi239"><img src="https://avatars3.githubusercontent.com/u/16478650?v=4" width="100px;" alt=""/><br /><sub><b>Denys Smirnov</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=dendi239" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/eddyp"><img src="https://avatars2.githubusercontent.com/u/123772?v=4" width="100px;" alt=""/><br /><sub><b>eddyp</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=eddyp" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://about.me/BrianKung"><img src="https://avatars1.githubusercontent.com/u/2836167?v=4" width="100px;" alt=""/><br /><sub><b>Brian Kung</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=briankung" title="Code">💻</a> <a href="#content-briankung" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://rcousineau.gitlab.io"><img src="https://avatars3.githubusercontent.com/u/281039?v=4" width="100px;" alt=""/><br /><sub><b>Russell</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=miller-time" title="Code">💻</a></td>
|
||||
<td align="center"><a href="http://danwilhelm.com"><img src="https://avatars3.githubusercontent.com/u/6137185?v=4" width="100px;" alt=""/><br /><sub><b>Dan Wilhelm</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=danwilhelm" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/Jesse-Cameron"><img src="https://avatars3.githubusercontent.com/u/3723654?v=4" width="100px;" alt=""/><br /><sub><b>Jesse</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Jesse-Cameron" title="Code">💻</a> <a href="#content-Jesse-Cameron" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/MrFroop"><img src="https://avatars3.githubusercontent.com/u/196700?v=4" width="100px;" alt=""/><br /><sub><b>Fredrik Jambrén</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=MrFroop" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/petemcfarlane"><img src="https://avatars3.githubusercontent.com/u/3472717?v=4" width="100px;" alt=""/><br /><sub><b>Pete McFarlane</b></sub></a><br /><a href="#content-petemcfarlane" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/nkanderson"><img src="https://avatars0.githubusercontent.com/u/4128825?v=4" width="100px;" alt=""/><br /><sub><b>nkanderson</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=nkanderson" title="Code">💻</a> <a href="#content-nkanderson" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/ajaxm"><img src="https://avatars0.githubusercontent.com/u/13360138?v=4" width="100px;" alt=""/><br /><sub><b>Ajax M</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=ajaxm" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://dylnuge.com"><img src="https://avatars2.githubusercontent.com/u/118624?v=4" width="100px;" alt=""/><br /><sub><b>Dylan Nugent</b></sub></a><br /><a href="#content-Dylnuge" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/vyaslav"><img src="https://avatars0.githubusercontent.com/u/1385427?v=4" width="100px;" alt=""/><br /><sub><b>vyaslav</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=vyaslav" title="Code">💻</a> <a href="#content-vyaslav" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://join.sfxd.org"><img src="https://avatars1.githubusercontent.com/u/17297466?v=4" width="100px;" alt=""/><br /><sub><b>George</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=gdoenlen" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/nyxtom"><img src="https://avatars2.githubusercontent.com/u/222763?v=4" width="100px;" alt=""/><br /><sub><b>Thomas Holloway</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=nyxtom" title="Code">💻</a> <a href="#content-nyxtom" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/workingjubilee"><img src="https://avatars1.githubusercontent.com/u/46493976?v=4" width="100px;" alt=""/><br /><sub><b>Jubilee</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=workingjubilee" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/WofWca"><img src="https://avatars1.githubusercontent.com/u/39462442?v=4" width="100px;" alt=""/><br /><sub><b>WofWca</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=WofWca" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/jrvidal"><img src="https://avatars0.githubusercontent.com/u/1636604?v=4" width="100px;" alt=""/><br /><sub><b>Roberto Vidal</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=jrvidal" title="Code">💻</a> <a href="https://github.com/fmoko/rustlings/commits?author=jrvidal" title="Documentation">📖</a> <a href="#ideas-jrvidal" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-jrvidal" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/jensim"><img src="https://avatars0.githubusercontent.com/u/3663856?v=4" width="100px;" alt=""/><br /><sub><b>Jens</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=jensim" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="http://rahatah.me/d"><img src="https://avatars3.githubusercontent.com/u/3174006?v=4" width="100px;" alt=""/><br /><sub><b>Rahat Ahmed</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=rahatarmanahmed" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/AbdouSeck"><img src="https://avatars2.githubusercontent.com/u/6490055?v=4" width="100px;" alt=""/><br /><sub><b>Abdou Seck</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=AbdouSeck" title="Code">💻</a> <a href="#content-AbdouSeck" title="Content">🖋</a> <a href="https://github.com/fmoko/rustlings/pulls?q=is%3Apr+reviewed-by%3AAbdouSeck" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://codehearts.com"><img src="https://avatars0.githubusercontent.com/u/2885412?v=4" width="100px;" alt=""/><br /><sub><b>Katie</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=codehearts" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/Socratides"><img src="https://avatars3.githubusercontent.com/u/27732983?v=4" width="100px;" alt=""/><br /><sub><b>Socrates</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Socratides" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/gnodarse"><img src="https://avatars3.githubusercontent.com/u/46761795?v=4" width="100px;" alt=""/><br /><sub><b>gnodarse</b></sub></a><br /><a href="#content-gnodarse" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://github.com/harrisonmetz"><img src="https://avatars1.githubusercontent.com/u/7883408?v=4" width="100px;" alt=""/><br /><sub><b>Harrison Metzger</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=harrisonmetz" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/TorbenJ"><img src="https://avatars2.githubusercontent.com/u/9077102?v=4" width="100px;" alt=""/><br /><sub><b>Torben Jonas</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=TorbenJ" title="Code">💻</a> <a href="#content-TorbenJ" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://paulbissex.com/"><img src="https://avatars0.githubusercontent.com/u/641?v=4" width="100px;" alt=""/><br /><sub><b>Paul Bissex</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=pbx" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/sjmann"><img src="https://avatars0.githubusercontent.com/u/6589896?v=4" width="100px;" alt=""/><br /><sub><b>Steven Mann</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=sjmann" title="Code">💻</a> <a href="#content-sjmann" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://smmdb.net/"><img src="https://avatars2.githubusercontent.com/u/5855071?v=4" width="100px;" alt=""/><br /><sub><b>Mario Reder</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=Tarnadas" title="Code">💻</a> <a href="#content-Tarnadas" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="https://keybase.io/skim"><img src="https://avatars0.githubusercontent.com/u/47347?v=4" width="100px;" alt=""/><br /><sub><b>skim</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=sl4m" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/sanjaykdragon"><img src="https://avatars1.githubusercontent.com/u/10261698?v=4" width="100px;" alt=""/><br /><sub><b>Sanjay K</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=sanjaykdragon" title="Code">💻</a> <a href="#content-sanjaykdragon" title="Content">🖋</a></td>
|
||||
<td align="center"><a href="http://www.rohanjain.in"><img src="https://avatars1.githubusercontent.com/u/343499?v=4" width="100px;" alt=""/><br /><sub><b>Rohan Jain</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=crodjer" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://www.saidaspen.se"><img src="https://avatars1.githubusercontent.com/u/7727687?v=4" width="100px;" alt=""/><br /><sub><b>Said Aspen</b></sub></a><br /><a href="https://github.com/fmoko/rustlings/commits?author=saidaspen" title="Code">💻</a> <a href="#content-saidaspen" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-enable -->
|
||||
<!-- prettier-ignore-end -->
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
My solutions to rustlings excercises
|
|
@ -1,5 +0,0 @@
|
|||
steps:
|
||||
- label: "Test with stable"
|
||||
command: rustup run stable cargo test
|
||||
- label: "Test with beta"
|
||||
command: rustup run beta cargo test
|
|
@ -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 compilation 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 |
|
|
@ -1,8 +1,10 @@
|
|||
### Clippy
|
||||
# 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/).
|
||||
## Further information
|
||||
|
||||
- [GitHub Repository](https://github.com/rust-lang/rust-clippy).
|
||||
|
|
22
exercises/collections/README.md
Normal file
22
exercises/collections/README.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
# 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 [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map),
|
||||
[*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages.
|
||||
|
||||
## Further information
|
||||
|
||||
- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html)
|
44
exercises/collections/hashmap1.rs
Normal file
44
exercises/collections/hashmap1.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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 hashmap1` if you need
|
||||
// hints.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn fruit_basket() -> HashMap<String, u32> {
|
||||
let mut basket = HashMap::new(); // 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.insert(String::from("peach"), 2);
|
||||
basket.insert(String::from("mango"), 2);
|
||||
basket.insert(String::from("apple"), 2);
|
||||
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);
|
||||
}
|
||||
}
|
79
exercises/collections/hashmap2.rs
Normal file
79
exercises/collections/hashmap2.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
// 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 Lychee (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 hashmap2` if you need
|
||||
// hints.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
enum Fruit {
|
||||
Apple,
|
||||
Banana,
|
||||
Mango,
|
||||
Lychee,
|
||||
Pineapple,
|
||||
}
|
||||
|
||||
fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
||||
let fruit_kinds = vec![
|
||||
Fruit::Apple,
|
||||
Fruit::Banana,
|
||||
Fruit::Mango,
|
||||
Fruit::Lychee,
|
||||
Fruit::Pineapple,
|
||||
];
|
||||
|
||||
for fruit in fruit_kinds {
|
||||
if fruit == Fruit::Banana || fruit == Fruit::Pineapple {
|
||||
basket.insert(fruit, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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::Lychee, 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::Lychee).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);
|
||||
}
|
||||
}
|
23
exercises/collections/vec1.rs
Normal file
23
exercises/collections/vec1.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// 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 vec1` if you need hints.
|
||||
|
||||
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
||||
let a = [10, 20, 30, 40]; // a plain array
|
||||
let v = vec![10,20,30,40]; // 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[..]);
|
||||
}
|
||||
}
|
35
exercises/collections/vec2.rs
Normal file
35
exercises/collections/vec2.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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 vec2` if you need
|
||||
// hints.
|
||||
|
||||
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.
|
||||
|
||||
// *i accesses a specific object in vector?
|
||||
// *= 2 multiplies it by 2
|
||||
*i *= 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>>());
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
### Type conversions
|
||||
|
||||
# Type conversions
|
||||
|
||||
Rust offers a multitude of ways to convert a value of a given type into another type.
|
||||
|
||||
|
@ -15,6 +14,8 @@ Furthermore, the `std::str` module offers a trait called [`FromStr`](https://doc
|
|||
|
||||
These should be the main ways ***within the standard library*** to convert data into your desired types.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
These are not directly covered in the book, but the standard library has great documentation for [conversions here](https://doc.rust-lang.org/std/convert/index.html). The `FromStr` trait is also covered [here](https://doc.rust-lang.org/std/str/trait.FromStr.html).
|
||||
These are not directly covered in the book, but the standard library has a great documentation for it.
|
||||
- [conversions](https://doc.rust-lang.org/std/convert/index.html)
|
||||
- [`FromStr` trait](https://doc.rust-lang.org/std/str/trait.FromStr.html)
|
|
@ -3,6 +3,7 @@
|
|||
// 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 {
|
||||
|
|
|
@ -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`
|
||||
|
@ -33,6 +32,9 @@ impl Default for 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 object with the results
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
impl From<&str> for Person {
|
||||
fn from(s: &str) -> Person {
|
||||
}
|
||||
|
@ -73,7 +75,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn test_bad_age() {
|
||||
// Test that "Mark.twenty" will return the default person due to an error in parsing 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);
|
||||
|
@ -113,4 +115,18 @@ mod tests {
|
|||
assert_eq!(p.name, "John");
|
||||
assert_eq!(p.age, 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_comma() {
|
||||
let p: Person = Person::from("Mike,32,");
|
||||
assert_eq!(p.name, "John");
|
||||
assert_eq!(p.age, 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_comma_and_some_string() {
|
||||
let p: Person = Person::from("Mike,32,man");
|
||||
assert_eq!(p.name, "John");
|
||||
assert_eq!(p.age, 30);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Additionally, upon implementing FromStr, you can use the `parse` method
|
||||
// on strings to generate an object of the implementor type.
|
||||
// You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html
|
||||
use std::error;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -11,17 +12,19 @@ struct Person {
|
|||
}
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Steps:
|
||||
// 1. If the length of the provided string is 0, then return an error
|
||||
// 1. If the length of the provided string is 0, an error should be returned
|
||||
// 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. If the name is empty, then return an error
|
||||
// 3. Only 2 elements should be returned from the split, otherwise return an error
|
||||
// 4. Extract the first element from the split operation and use it as the name
|
||||
// 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
|
||||
// with something like `"4".parse::<usize>()`
|
||||
// 5. If while extracting the name and the age something goes wrong, an error should be returned
|
||||
// If everything goes well, then return a Result of a Person object
|
||||
|
||||
impl FromStr for Person {
|
||||
type Err = String;
|
||||
type Err = Box<dyn error::Error>;
|
||||
fn from_str(s: &str) -> Result<Person, Self::Err> {
|
||||
}
|
||||
}
|
||||
|
@ -48,39 +51,42 @@ mod tests {
|
|||
assert_eq!(p.age, 32);
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_age() {
|
||||
"John,".parse::<Person>().unwrap();
|
||||
assert!("John,".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn invalid_age() {
|
||||
"John,twenty".parse::<Person>().unwrap();
|
||||
assert!("John,twenty".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_comma_and_age() {
|
||||
"John".parse::<Person>().unwrap();
|
||||
assert!("John".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_name() {
|
||||
",1".parse::<Person>().unwrap();
|
||||
assert!(",1".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_name_and_age() {
|
||||
",".parse::<Person>().unwrap();
|
||||
assert!(",".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_name_and_invalid_age() {
|
||||
",one".parse::<Person>().unwrap();
|
||||
assert!(",one".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_comma() {
|
||||
assert!("John,32,".parse::<Person>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_comma_and_some_string() {
|
||||
assert!("John,32,man".parse::<Person>().is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
// 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};
|
||||
use std::error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Color {
|
||||
red: u8,
|
||||
green: u8,
|
||||
|
@ -15,32 +16,29 @@ struct Color {
|
|||
|
||||
// Your task is to complete this implementation
|
||||
// and return an Ok result of inner type Color.
|
||||
// You need create implementation for a tuple of three integer,
|
||||
// an array of three integer and slice of integer.
|
||||
// You need to create an implementation for a tuple of three integers,
|
||||
// an array of three integers and a slice of integers.
|
||||
//
|
||||
// Note, that implementation for tuple and array will be checked at compile-time,
|
||||
// but slice implementation need check slice length!
|
||||
// Also note, that chunk of correct rgb color must be integer in range 0..=255.
|
||||
// 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(tuple: (i16, i16, i16)) -> Result<Self, Self::Error> {
|
||||
}
|
||||
type Error = Box<dyn error::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> {
|
||||
}
|
||||
type Error = Box<dyn error::Error>;
|
||||
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> {
|
||||
}
|
||||
type Error = Box<dyn error::Error>;
|
||||
fn try_from(slice: &[i16]) -> Result<Self, Self::Error> {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -66,65 +64,95 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_tuple_out_of_range_positive() {
|
||||
let _ = Color::try_from((256, 1000, 10000)).unwrap();
|
||||
assert!(Color::try_from((256, 1000, 10000)).is_err());
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_tuple_out_of_range_negative() {
|
||||
let _ = Color::try_from((-1, -10, -256)).unwrap();
|
||||
assert!(Color::try_from((-1, -10, -256)).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_tuple_sum() {
|
||||
assert!(Color::try_from((-1, 255, 255)).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_tuple_correct() {
|
||||
let c: Color = (183, 65, 14).try_into().unwrap();
|
||||
assert_eq!(c.red, 183);
|
||||
assert_eq!(c.green, 65);
|
||||
assert_eq!(c.blue, 14);
|
||||
let c: Result<Color, _> = (183, 65, 14).try_into();
|
||||
assert!(c.is_ok());
|
||||
assert_eq!(
|
||||
c.unwrap(),
|
||||
Color {
|
||||
red: 183,
|
||||
green: 65,
|
||||
blue: 14
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_array_out_of_range_positive() {
|
||||
let _: Color = [1000, 10000, 256].try_into().unwrap();
|
||||
let c: Result<Color, _> = [1000, 10000, 256].try_into();
|
||||
assert!(c.is_err());
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_array_out_of_range_negative() {
|
||||
let _: Color = [-10, -256, -1].try_into().unwrap();
|
||||
let c: Result<Color, _> = [-10, -256, -1].try_into();
|
||||
assert!(c.is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_array_sum() {
|
||||
let c: Result<Color, _> = [-1, 255, 255].try_into();
|
||||
assert!(c.is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_array_correct() {
|
||||
let c: Color = [183, 65, 14].try_into().unwrap();
|
||||
assert_eq!(c.red, 183);
|
||||
assert_eq!(c.green, 65);
|
||||
assert_eq!(c.blue, 14);
|
||||
let c: Result<Color, _> = [183, 65, 14].try_into();
|
||||
assert!(c.is_ok());
|
||||
assert_eq!(
|
||||
c.unwrap(),
|
||||
Color {
|
||||
red: 183,
|
||||
green: 65,
|
||||
blue: 14
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_slice_out_of_range_positive() {
|
||||
let arr = [10000, 256, 1000];
|
||||
let _ = Color::try_from(&arr[..]).unwrap();
|
||||
assert!(Color::try_from(&arr[..]).is_err());
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_slice_out_of_range_negative() {
|
||||
let arr = [-256, -1, -10];
|
||||
let _ = Color::try_from(&arr[..]).unwrap();
|
||||
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 = Color::try_from(&v[..]).unwrap();
|
||||
assert_eq!(c.red, 183);
|
||||
assert_eq!(c.green, 65);
|
||||
assert_eq!(c.blue, 14);
|
||||
let c: Result<Color, _> = Color::try_from(&v[..]);
|
||||
assert!(c.is_ok());
|
||||
assert_eq!(
|
||||
c.unwrap(),
|
||||
Color {
|
||||
red: 183,
|
||||
green: 65,
|
||||
blue: 14
|
||||
}
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_slice_excess_length() {
|
||||
let v = vec![0, 0, 0, 0];
|
||||
let _ = Color::try_from(&v[..]).unwrap();
|
||||
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,10 +1,10 @@
|
|||
### Enums
|
||||
# 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
|
||||
## Further information
|
||||
|
||||
- [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html)
|
||||
- [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
// enums1.rs
|
||||
// Make me compile! Execute `rustlings hint enums1` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
// TODO: define a few types of messages as used below
|
||||
Quit,
|
||||
Echo,
|
||||
Move,
|
||||
ChangeColor
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
// enums2.rs
|
||||
// Make me compile! Execute `rustlings hint enums2` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
// TODO: define the different variants used below
|
||||
Move { x: i32, y: i32 },
|
||||
Echo(String),
|
||||
ChangeColor(i32,i32,i32),
|
||||
Quit
|
||||
}
|
||||
|
||||
impl Message {
|
||||
|
@ -16,10 +17,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 {
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
// enums3.rs
|
||||
// Address all the TODOs to make the tests pass!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
enum Message {
|
||||
// TODO: implement the message variant types based on their usage below
|
||||
Move(Point),
|
||||
Echo(String),
|
||||
ChangeColor((u8,u8,u8)),
|
||||
Quit
|
||||
}
|
||||
|
||||
struct Point {
|
||||
x: u8,
|
||||
y: u8
|
||||
y: u8,
|
||||
}
|
||||
|
||||
struct State {
|
||||
color: (u8, u8, u8),
|
||||
position: Point,
|
||||
quit: bool
|
||||
quit: bool,
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
@ -37,6 +38,13 @@ impl State {
|
|||
|
||||
fn process(&mut self, message: Message) {
|
||||
// TODO: create a match expression to process the different message variants
|
||||
match message {
|
||||
Message::ChangeColor((r,g,b)) => self.change_color((r,g,b)),
|
||||
Message::Echo(String) => self.echo(String),
|
||||
Message::Move(Pointer) => self.move_position(Pointer),
|
||||
Message::Quit => self.quit(),
|
||||
_ => panic!("NOTHING SUPPLIED D:"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,14 +54,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(Point{ 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 +69,4 @@ mod tests {
|
|||
assert_eq!(state.position.y, 15);
|
||||
assert_eq!(state.quit, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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
|
||||
Most errors aren’t serious enough to require the program to stop entirely.
|
||||
Sometimes, when a function fails, it’s for a reason that you can easily interpret and respond to.
|
||||
For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the file instead of terminating the process.
|
||||
|
||||
of the Rust Book.
|
||||
## Further information
|
||||
|
||||
- [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)
|
||||
- [Result](https://doc.rust-lang.org/rust-by-example/error/result.html)
|
||||
- [Boxing errors](https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html)
|
||||
|
|
|
@ -6,14 +6,12 @@
|
|||
// this function to have.
|
||||
// Execute `rustlings hint errors1` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
pub fn generate_nametag_text(name: String) -> Option<String> {
|
||||
pub fn generate_nametag_text(name: String) -> Result<String, String> {
|
||||
if name.len() > 0 {
|
||||
Some(format!("Hi! My name is {}", name))
|
||||
Ok(format!("Hi! My name is {}", name))
|
||||
} else {
|
||||
// Empty names aren't allowed.
|
||||
None
|
||||
Err("Empty names aren't allowed.".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,11 +26,12 @@ mod tests {
|
|||
fn generates_nametag_text_for_a_nonempty_name() {
|
||||
assert_eq!(
|
||||
generate_nametag_text("Beyoncé".into()),
|
||||
Some("Hi! My name is Beyoncé".into())
|
||||
Ok("Hi! My name is Beyoncé".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn explains_why_generating_nametag_text_fails() {
|
||||
assert_eq!(
|
||||
generate_nametag_text("".into()),
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
// There are at least two ways to implement this that are both correct-- but
|
||||
// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::num::ParseIntError;
|
||||
|
||||
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
||||
let processing_fee = 1;
|
||||
let cost_per_item = 5;
|
||||
let qty = item_quantity.parse::<i32>();
|
||||
let qty = item_quantity.parse::<i32>()?;
|
||||
|
||||
Ok(qty * cost_per_item + processing_fee)
|
||||
}
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
// Why not? What should we do to fix it?
|
||||
// Execute `rustlings hint errors3` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::num::ParseIntError;
|
||||
|
||||
fn main() {
|
||||
// In previous excercises we were taught that Result can output
|
||||
// i32 and ParseIntError, but nobody told us that Result can also
|
||||
// output () instead of i32... oops
|
||||
fn main() -> Result<(), ParseIntError> {
|
||||
let mut tokens = 100;
|
||||
let pretend_user_input = "8";
|
||||
|
||||
|
@ -20,6 +21,8 @@ fn main() {
|
|||
tokens -= cost;
|
||||
println!("You now have {} tokens.", tokens);
|
||||
}
|
||||
// No need for Err() because `?` operator already handles it well
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
||||
|
|
|
@ -17,19 +17,17 @@
|
|||
//
|
||||
// Execute `rustlings hint errorsn` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
||||
// PositiveNonzeroInteger is a struct defined below the tests.
|
||||
fn read_and_validate(b: &mut dyn io::BufRead) -> Result<PositiveNonzeroInteger, ???> {
|
||||
fn read_and_validate(b: &mut dyn io::BufRead) -> Result<PositiveNonzeroInteger, Box<dyn error::Error>> {
|
||||
let mut line = String::new();
|
||||
b.read_line(&mut line);
|
||||
let num: i64 = line.trim().parse();
|
||||
let answer = PositiveNonzeroInteger::new(num);
|
||||
answer
|
||||
b.read_line(&mut line)?;
|
||||
let num: i64 = line.trim().parse()?;
|
||||
let answer = PositiveNonzeroInteger::new(num)?;
|
||||
Ok(answer)
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### Functions
|
||||
# Functions
|
||||
|
||||
Here, you'll learn how to write functions and how Rust's compiler can trace things way back.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [How Functions Work](https://doc.rust-lang.org/book/ch03-03-how-functions-work.html)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// functions1.rs
|
||||
// Make me compile! Execute `rustlings hint functions1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
call_me();
|
||||
}
|
||||
fn call_me() {
|
||||
println!("Called!");
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
// functions2.rs
|
||||
// Make me compile! Execute `rustlings hint functions2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
call_me(3);
|
||||
call_me(7);
|
||||
}
|
||||
|
||||
fn call_me(num) {
|
||||
fn call_me(num:i32) {
|
||||
for i in 0..num {
|
||||
println!("Ring! Call number {}", i + 1);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
// functions3.rs
|
||||
// Make me compile! Execute `rustlings hint functions3` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
call_me();
|
||||
call_me(6);
|
||||
}
|
||||
|
||||
fn call_me(num: i32) {
|
||||
fn call_me(num: u32) {
|
||||
for i in 0..num {
|
||||
println!("Ring! Call number {}", i + 1);
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@
|
|||
// This store is having a sale where if the price is an even number, you get
|
||||
// 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let original_price = 51;
|
||||
println!("Your sale price is {}", sale_price(original_price));
|
||||
}
|
||||
|
||||
fn sale_price(price: i32) -> {
|
||||
fn sale_price(price: i32) -> i32 {
|
||||
if is_even(price) {
|
||||
price - 10
|
||||
} else {
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
// functions5.rs
|
||||
// Make me compile! Execute `rustlings hint functions5` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let answer = square(3);
|
||||
println!("The answer is {}", answer);
|
||||
}
|
||||
|
||||
// without ; the expression is a return statement
|
||||
// it can be either both num * num or
|
||||
// return num * num;
|
||||
// but it cannot be
|
||||
// return num * num OR num * num;
|
||||
|
||||
fn square(num: i32) -> i32 {
|
||||
num * num;
|
||||
num * num
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
### Generics
|
||||
# Generics
|
||||
|
||||
In this section you'll learn about saving yourself many lines of code with generics!
|
||||
Generics is the topic of generalizing types and functionalities to broader cases.
|
||||
This is extremely useful for reducing code duplication in many ways, but can call for rather involving syntax.
|
||||
Namely, being generic requires taking great care to specify over which types a generic type is actually considered valid.
|
||||
The simplest and most common use of generics is for type parameters.
|
||||
|
||||
### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html)
|
||||
- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html)
|
||||
- [Bounds](https://doc.rust-lang.org/rust-by-example/generics/bounds.html)
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// This shopping list program isn't compiling!
|
||||
// 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();
|
||||
let mut shopping_list: Vec<&str> = Vec::new();
|
||||
shopping_list.push("milk");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
// 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
|
||||
struct Wrapper<T> {
|
||||
value: T,
|
||||
}
|
||||
|
||||
impl Wrapper {
|
||||
pub fn new(value: u32) -> Self {
|
||||
// <T> must be both for impl and Wrapper
|
||||
impl<T> Wrapper<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
Wrapper { value }
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +17,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn store_u32_in_wrapper() {
|
||||
assert_eq!(Wrapper::new(42).value, 42);
|
||||
assert_eq!(Wrapper::new(42).value, 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn store_str_in_wrapper() {
|
||||
assert_eq!(Wrapper::new("Foo").value, "Foo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
// 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
|
||||
// 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 to support alphabetical report cards, thereby making
|
||||
// the second test pass.
|
||||
// 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.
|
||||
|
||||
// I AM NOT DONE
|
||||
pub struct ReportCard {
|
||||
pub grade: f32,
|
||||
// Execute 'rustlings hint generics3' for hints!
|
||||
|
||||
pub struct ReportCard<T> {
|
||||
pub grade: T,
|
||||
pub student_name: String,
|
||||
pub student_age: u8,
|
||||
}
|
||||
|
||||
impl ReportCard {
|
||||
// <T> must implement std::fmt::Display or no format!() macro
|
||||
// for you
|
||||
impl<T: std::fmt::Display> ReportCard<T> {
|
||||
pub fn print(&self) -> String {
|
||||
format!("{} ({}) - achieved a grade of {}",
|
||||
format!("{} ({}) - achieved a grade of {}",
|
||||
&self.student_name, &self.student_age, &self.grade)
|
||||
}
|
||||
}
|
||||
|
@ -28,21 +32,27 @@ mod tests {
|
|||
#[test]
|
||||
fn generate_numeric_report_card() {
|
||||
let report_card = ReportCard {
|
||||
grade: 2.1,
|
||||
student_name: "Tom Wriggle".to_string(),
|
||||
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");
|
||||
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(),
|
||||
grade: "A+".to_string(),
|
||||
student_name: "Gary Plotter".to_string(),
|
||||
student_age: 11,
|
||||
};
|
||||
assert_eq!(report_card.print(), "Gary Plotter (11) - achieved a grade of A+");
|
||||
assert_eq!(
|
||||
report_card.print(),
|
||||
"Gary Plotter (11) - achieved a grade of A+"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### If
|
||||
# If
|
||||
|
||||
`if`, the most basic type of control flow, is what you'll learn here.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Control Flow - if expressions](https://doc.rust-lang.org/book/ch03-05-control-flow.html#if-expressions)
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
// if1.rs
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
pub fn bigger(a: i32, b: i32) -> i32 {
|
||||
// Complete this function to return the bigger number!
|
||||
// Do not use:
|
||||
// - another function call
|
||||
// - additional variables
|
||||
// Execute `rustlings hint if1` for hints
|
||||
pub fn bigger(a: i32, b: i32) -> i32 {
|
||||
if a > b {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
// Don't mind this for now :)
|
||||
|
|
|
@ -4,13 +4,14 @@
|
|||
// 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 if fizzish == "fuzz" {
|
||||
"bar"
|
||||
} else {
|
||||
1
|
||||
"baz"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
### Macros
|
||||
# Macros
|
||||
|
||||
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
|
||||
macros. Instead, we'll show you how to use and create them.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html)
|
||||
- [The Little Book of Rust Macros](https://danielkeep.github.io/tlborm/book/index.html)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### Modules
|
||||
# Modules
|
||||
|
||||
In this section we'll give you an introduction to Rust's module system.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [The Module System](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html)
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// modules1.rs
|
||||
// Make me compile! Execute `rustlings hint modules1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
// `mod` defines a module which can contain functions, structs etc.
|
||||
// by default, its `fn`s only limited within itself, creating "closed
|
||||
// ecosystem". you can make them public with `pub`
|
||||
|
||||
mod sausage_factory {
|
||||
fn make_sausage() {
|
||||
pub fn make_sausage() {
|
||||
println!("sausage!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
// modules2.rs
|
||||
// Make me compile! Execute `rustlings hint modules2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
mod delicious_snacks {
|
||||
use self::fruits::PEAR as fruit;
|
||||
use self::veggies::CUCUMBER as veggie;
|
||||
pub use self::fruits::PEAR as fruit;
|
||||
pub use self::veggies::CUCUMBER as veggie;
|
||||
|
||||
mod fruits {
|
||||
pub const PEAR: &'static str = "Pear";
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
### Move Semantics
|
||||
# Move Semantics
|
||||
|
||||
These exercises are adapted from [pnkfelix](https://github.com/pnkfelix)'s [Rust Tutorial](https://pnkfelix.github.io/rust-examples-icfp2014/) -- Thank you Felix!!!
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
For this section, the book links are especially important.
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// move_semantics1.rs
|
||||
// Make me compile! Execute `rustlings hint move_semantics1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
// Make me compile without changing line 13!
|
||||
// Execute `rustlings hint move_semantics2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
let mut vec1 = fill_vec(&vec0);
|
||||
|
||||
// Do not change the following line!
|
||||
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
|
||||
|
@ -17,8 +15,8 @@ fn main() {
|
|||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
let mut vec = vec;
|
||||
fn fill_vec(vec: &[i32]) -> Vec<i32> {
|
||||
let mut vec = vec.to_vec();
|
||||
|
||||
vec.push(22);
|
||||
vec.push(44);
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
// (no lines with multiple semicolons necessary!)
|
||||
// Execute `rustlings hint move_semantics3` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
let mut vec1 = fill_vec(&vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
|
||||
|
@ -17,7 +15,8 @@ fn main() {
|
|||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
fn fill_vec(vec: &[i32]) -> Vec<i32> {
|
||||
let mut vec = vec.to_vec();
|
||||
vec.push(22);
|
||||
vec.push(44);
|
||||
vec.push(66);
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
// move_semantics4.rs
|
||||
// Refactor this code so that instead of having `vec0` and creating the vector
|
||||
// in `fn main`, we instead create it within `fn fill_vec` and transfer the
|
||||
// in `fn main`, we create it within `fn fill_vec` and transfer the
|
||||
// freshly created vector from fill_vec to its caller.
|
||||
// Execute `rustlings hint move_semantics4` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let vec0 = Vec::new();
|
||||
// let vec0 = Vec::new();
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
let mut vec1 = fill_vec();
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
|
||||
|
@ -18,9 +17,9 @@ fn main() {
|
|||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
}
|
||||
|
||||
// `fill_vec()` no longer take `vec: Vec<i32>` as argument
|
||||
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
|
||||
fn fill_vec() -> Vec<i32> {
|
||||
let mut vec = vec;
|
||||
let mut vec = Vec::new();
|
||||
|
||||
vec.push(22);
|
||||
vec.push(44);
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
### Option
|
||||
# Option
|
||||
|
||||
#### Book Sections
|
||||
Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not.
|
||||
Option types are very common in Rust code, as they have a number of uses:
|
||||
- Initial values
|
||||
- Return values for functions that are not defined over their entire input range (partial functions)
|
||||
- Return value for otherwise reporting simple errors, where None is returned on error
|
||||
- Optional struct fields
|
||||
- Struct fields that can be loaned or "taken"
|
||||
- Optional function arguments
|
||||
- Nullable pointers
|
||||
- Swapping things out of difficult situations
|
||||
|
||||
To learn about Option<T>, check out these links:
|
||||
## Further Information
|
||||
|
||||
- [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/)
|
||||
|
|
|
@ -9,15 +9,16 @@ fn print_number(maybe_number: Option<u16>) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
print_number(13);
|
||||
print_number(99);
|
||||
// rustc suggested solutions
|
||||
print_number(Some(13));
|
||||
print_number(Some(99));
|
||||
|
||||
let mut numbers: [Option<u16>; 5];
|
||||
let 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;
|
||||
numbers[iter as usize] = Some(number_to_add);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,22 +4,22 @@
|
|||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let optional_value = Some(String::from("rustlings"));
|
||||
let optional_word = 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);
|
||||
word = optional_word {
|
||||
println!("The word is: {}", word);
|
||||
} else {
|
||||
println!("The optional value doesn't contain anything!");
|
||||
println!("The optional word doesn't contain anything");
|
||||
}
|
||||
|
||||
let mut optional_values_vec: Vec<Option<i8>> = Vec::new();
|
||||
let mut optional_integers_vec: Vec<Option<i8>> = Vec::new();
|
||||
for x in 1..10 {
|
||||
optional_values_vec.push(Some(x));
|
||||
optional_integers_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);
|
||||
integer = optional_integers_vec.pop() {
|
||||
println!("current value: {}", integer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
### Primitive Types
|
||||
# Primitive Types
|
||||
|
||||
Rust has a couple of basic types that are directly implemented into the
|
||||
compiler. In this section, we'll go through the most important ones.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html)
|
||||
- [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html)
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// Fill in the rest of the line that has code missing!
|
||||
// No hints, there's no tricks, just get used to typing these :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
// Booleans (`bool`)
|
||||
|
||||
|
@ -12,7 +10,7 @@ fn main() {
|
|||
println!("Good morning!");
|
||||
}
|
||||
|
||||
let // Finish the rest of this line like the example! Or make it be false!
|
||||
let is_evening = true; // Finish the rest of this line like the example! Or make it be false!
|
||||
if is_evening {
|
||||
println!("Good evening!");
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// Fill in the rest of the line that has code missing!
|
||||
// No hints, there's no tricks, just get used to typing these :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
// Characters (`char`)
|
||||
|
||||
|
@ -16,7 +14,7 @@ fn main() {
|
|||
println!("Neither alphabetic nor numeric!");
|
||||
}
|
||||
|
||||
let // Finish this line like the example! What's your favorite character?
|
||||
let your_character = 'D'; // Finish this line like the example! What's your favorite character?
|
||||
// Try a letter, try a number, try a special character, try a character
|
||||
// from a different language than your own, try an emoji!
|
||||
if your_character.is_alphabetic() {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
// 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
|
||||
|
||||
fn main() {
|
||||
let a = ???
|
||||
let a: [i32; 300] = [0; 300];
|
||||
|
||||
if a.len() >= 100 {
|
||||
println!("Wow, that's a big array!");
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
// Get a slice out of Array a where the ??? is so that the test passes.
|
||||
// Execute `rustlings hint primitive_types4` for hints!!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[test]
|
||||
fn slice_out_of_array() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
let nice_slice = ???
|
||||
let nice_slice = &a[1..4];
|
||||
|
||||
assert_eq!([2, 3, 4], nice_slice)
|
||||
}
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
// Destructure the `cat` tuple so that the println will work.
|
||||
// Execute `rustlings hint primitive_types5` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let cat = ("Furry McFurson", 3.5);
|
||||
let /* your pattern here */ = cat;
|
||||
let (name, age) = cat;
|
||||
|
||||
println!("{} is {} years old.", name, age);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
// 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 = numbers.1;
|
||||
|
||||
assert_eq!(2, second,
|
||||
"This is not the 2nd number in the tuple!")
|
||||
}
|
||||
|
|
|
@ -7,10 +7,16 @@
|
|||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||
// the price of an order of apples given the order amount. No hints this time!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Put your function here!
|
||||
// fn ..... {
|
||||
fn calculate_apple_price(amount: i32) -> i32 {
|
||||
if amount > 40 {
|
||||
1 * amount
|
||||
} else {
|
||||
2 * amount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Don't modify this function!
|
||||
#[test]
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
// 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);
|
||||
}
|
||||
|
@ -17,14 +15,14 @@ fn string(arg: String) {
|
|||
}
|
||||
|
||||
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());
|
||||
string_slice("blue");
|
||||
string("red".to_string());
|
||||
string(String::from("hi"));
|
||||
string("rust is fun!".to_owned());
|
||||
string("nice weather".into());
|
||||
string(format!("Interpolation {}", "Station"));
|
||||
string_slice(&String::from("abc")[0..1]);
|
||||
string_slice(" hello there ".trim());
|
||||
string("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn returns_twice_of_negative_numbers() {
|
||||
// TODO write an assert for `times_two(-4)`
|
||||
// TODO replace unimplemented!() with an assert for `times_two(-4)`
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
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).
|
||||
# Standard library types
|
||||
|
||||
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.
|
||||
This section will teach you about Box, Shared-State Concurrency and Iterators.
|
||||
|
||||
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!
|
||||
## Further information
|
||||
|
||||
- [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html)
|
||||
- [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html)
|
||||
- [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html)
|
||||
- [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/)
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
// arc1.rs
|
||||
// In this exercise, we are given a Vec of u32 called "numbers" with values ranging
|
||||
// from 0 to 99 -- [ 0, 1, 2, ..., 98, 99 ]
|
||||
// We would like to use this set of numbers within 8 different threads simultaneously.
|
||||
// Each thread is going to get the sum of every eighth value, with an offset.
|
||||
// The first thread (offset 0), will sum 0, 8, 16, ...
|
||||
// The second thread (offset 1), will sum 1, 9, 17, ...
|
||||
// The third thread (offset 2), will sum 2, 10, 18, ...
|
||||
// ...
|
||||
// The eighth thread (offset 7), will sum 7, 15, 23, ...
|
||||
|
||||
// Because we are using threads, our values need to be thread-safe. Therefore,
|
||||
// we are using Arc. We need to make a change in each of the two TODOs.
|
||||
|
||||
|
||||
// Make this code compile by filling in a value for `shared_numbers` where the
|
||||
// TODO comment is and create an initial binding for `child_numbers`
|
||||
// somewhere. Try not to create any copies of the `numbers` Vec!
|
||||
// first TODO comment is, and create an initial binding for `child_numbers`
|
||||
// where the second TODO comment is. Try not to create any copies of the `numbers` Vec!
|
||||
// Execute `rustlings hint arc1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
@ -16,12 +30,13 @@ fn main() {
|
|||
let mut joinhandles = Vec::new();
|
||||
|
||||
for offset in 0..8 {
|
||||
let child_numbers = // TODO
|
||||
joinhandles.push(thread::spawn(move || {
|
||||
let mut i = offset;
|
||||
let mut sum = 0;
|
||||
while i < child_numbers.len() {
|
||||
sum += child_numbers[i];
|
||||
i += 5;
|
||||
i += 8;
|
||||
}
|
||||
println!("Sum of offset {} is {}", offset, sum);
|
||||
}));
|
||||
|
|
|
@ -26,7 +26,10 @@ pub enum List {
|
|||
|
||||
fn main() {
|
||||
println!("This is an empty cons list: {:?}", create_empty_list());
|
||||
println!("This is a non-empty cons list: {:?}", create_non_empty_list());
|
||||
println!(
|
||||
"This is a non-empty cons list: {:?}",
|
||||
create_non_empty_list()
|
||||
);
|
||||
}
|
||||
|
||||
pub fn create_empty_list() -> 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,28 +1,41 @@
|
|||
// 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.
|
||||
// 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.
|
||||
// In this exercise, you'll learn some of the unique advantages that iterators
|
||||
// can offer. Follow the steps to complete the exercise.
|
||||
// As always, there are hints if you execute `rustlings hint iterators2`!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Step 1.
|
||||
// Complete the `capitalize_first` function.
|
||||
// "hello" -> "Hello"
|
||||
pub fn capitalize_first(input: &str) -> String {
|
||||
let mut c = input.chars();
|
||||
match c.next() {
|
||||
None => String::new(),
|
||||
Some(first) => first.collect::<String>() + c.as_str(),
|
||||
Some(first) => ???,
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
// Apply the `capitalize_first` function to a slice of string slices.
|
||||
// Return a vector of strings.
|
||||
// ["hello", "world"] -> ["Hello", "World"]
|
||||
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
// Apply the `capitalize_first` function again to a slice of string slices.
|
||||
// Return a single string.
|
||||
// ["hello", " ", "world"] -> "Hello World"
|
||||
pub fn capitalize_words_string(words: &[&str]) -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// Step 1.
|
||||
// Tests that verify your `capitalize_first` function implementation
|
||||
#[test]
|
||||
fn test_success() {
|
||||
assert_eq!(capitalize_first("hello"), "Hello");
|
||||
|
@ -33,18 +46,15 @@ mod tests {
|
|||
assert_eq!(capitalize_first(""), "");
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
#[test]
|
||||
fn test_iterate_string_vec() {
|
||||
let words = vec!["hello", "world"];
|
||||
let capitalized_words: Vec<String> = // TODO
|
||||
assert_eq!(capitalized_words, ["Hello", "World"]);
|
||||
assert_eq!(capitalize_words_vector(&words), ["Hello", "World"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterate_into_string() {
|
||||
let words = vec!["hello", " ", "world"];
|
||||
let capitalized_words = // TODO
|
||||
assert_eq!(capitalized_words, "Hello World");
|
||||
assert_eq!(capitalize_words_string(&words), "Hello World");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
// iterators3.rs
|
||||
// This is a bigger exercise than most of the others! You can do it!
|
||||
// Here is your mission, should you choose to accept it:
|
||||
// 1. Complete the divide function to get the first four tests to pass
|
||||
// 2. Uncomment the last two tests and get them to pass by filling in
|
||||
// values for `x` using `division_results`.
|
||||
// 1. Complete the divide function to get the first four tests to pass.
|
||||
// 2. Get the remaining tests to pass by completing the result_with_list and
|
||||
// list_of_results functions.
|
||||
// Execute `rustlings hint iterators3` to get some hints!
|
||||
// Have fun :-)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
@ -21,16 +20,28 @@ pub struct NotDivisibleError {
|
|||
divisor: i32,
|
||||
}
|
||||
|
||||
// This function should calculate `a` divided by `b` if `a` is
|
||||
// evenly divisible by b.
|
||||
// Otherwise, it should return a suitable error.
|
||||
// Calculate `a` divided by `b` if `a` is evenly divisible by `b`.
|
||||
// Otherwise, return a suitable error.
|
||||
pub fn divide(a: i32, b: i32) -> Result<i32, DivisionError> {}
|
||||
|
||||
// Complete the function and return a value of the correct type so the test passes.
|
||||
// Desired output: Ok([1, 11, 1426, 3])
|
||||
fn result_with_list() -> () {
|
||||
let numbers = vec![27, 297, 38502, 81];
|
||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
||||
}
|
||||
|
||||
// Complete the function and return a value of the correct type so the test passes.
|
||||
// Desired output: [Ok(1), Ok(11), Ok(1426), Ok(3)]
|
||||
fn list_of_results() -> () {
|
||||
let numbers = vec![27, 297, 38502, 81];
|
||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// Tests that verify your `divide` function implementation
|
||||
#[test]
|
||||
fn test_success() {
|
||||
assert_eq!(divide(81, 9), Ok(9));
|
||||
|
@ -57,22 +68,16 @@ mod tests {
|
|||
assert_eq!(divide(0, 81), Ok(0));
|
||||
}
|
||||
|
||||
// Iterator exercises using your `divide` function
|
||||
/*
|
||||
#[test]
|
||||
fn result_with_list() {
|
||||
let numbers = vec![27, 297, 38502, 81];
|
||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
||||
let x //... Fill in here!
|
||||
assert_eq!(format!("{:?}", x), "Ok([1, 11, 1426, 3])");
|
||||
fn test_result_with_list() {
|
||||
assert_eq!(format!("{:?}", result_with_list()), "Ok([1, 11, 1426, 3])");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_of_results() {
|
||||
let numbers = vec![27, 297, 38502, 81];
|
||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
||||
let x //... Fill in here!
|
||||
assert_eq!(format!("{:?}", x), "[Ok(1), Ok(11), Ok(1426), Ok(3)]");
|
||||
fn test_list_of_results() {
|
||||
assert_eq!(
|
||||
format!("{:?}", list_of_results()),
|
||||
"[Ok(1), Ok(11), Ok(1426), Ok(3)]"
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
124
exercises/standard_library_types/iterators5.rs
Normal file
124
exercises/standard_library_types/iterators5.rs
Normal file
|
@ -0,0 +1,124 @@
|
|||
// iterators5.rs
|
||||
|
||||
// Let's define a simple model to track Rustlings exercise progress. Progress
|
||||
// will be modelled using a hash map. The name of the exercise is the key and
|
||||
// the progress is the value. Two counting functions were created to count the
|
||||
// number of exercises with a given progress. These counting functions use
|
||||
// imperative style for loops. Recreate this counting functionality using
|
||||
// iterators. Only the two iterator methods (count_iterator and
|
||||
// count_collection_iterator) need to be modified.
|
||||
// Execute `rustlings hint
|
||||
// iterators5` for hints.
|
||||
//
|
||||
// Make the code compile and the tests pass.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
enum Progress {
|
||||
None,
|
||||
Some,
|
||||
Complete,
|
||||
}
|
||||
|
||||
fn count_for(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
||||
let mut count = 0;
|
||||
for val in map.values() {
|
||||
if val == &value {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
||||
// map is a hashmap with String keys and Progress values.
|
||||
// map = { "variables1": Complete, "from_str": None, ... }
|
||||
}
|
||||
|
||||
fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
|
||||
let mut count = 0;
|
||||
for map in collection {
|
||||
for val in map.values() {
|
||||
if val == &value {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
|
||||
// collection is a slice of hashmaps.
|
||||
// collection = [{ "variables1": Complete, "from_str": None, ... },
|
||||
// { "variables2": Complete, ... }, ... ]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn count_complete() {
|
||||
let map = get_map();
|
||||
assert_eq!(3, count_iterator(&map, Progress::Complete));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_equals_for() {
|
||||
let map = get_map();
|
||||
assert_eq!(
|
||||
count_for(&map, Progress::Complete),
|
||||
count_iterator(&map, Progress::Complete)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_collection_complete() {
|
||||
let collection = get_vec_map();
|
||||
assert_eq!(
|
||||
6,
|
||||
count_collection_iterator(&collection, Progress::Complete)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_collection_equals_for() {
|
||||
let collection = get_vec_map();
|
||||
assert_eq!(
|
||||
count_collection_for(&collection, Progress::Complete),
|
||||
count_collection_iterator(&collection, Progress::Complete)
|
||||
);
|
||||
}
|
||||
|
||||
fn get_map() -> HashMap<String, Progress> {
|
||||
use Progress::*;
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert(String::from("variables1"), Complete);
|
||||
map.insert(String::from("functions1"), Complete);
|
||||
map.insert(String::from("hashmap1"), Complete);
|
||||
map.insert(String::from("arc1"), Some);
|
||||
map.insert(String::from("as_ref_mut"), None);
|
||||
map.insert(String::from("from_str"), None);
|
||||
|
||||
map
|
||||
}
|
||||
|
||||
fn get_vec_map() -> Vec<HashMap<String, Progress>> {
|
||||
use Progress::*;
|
||||
|
||||
let map = get_map();
|
||||
|
||||
let mut other = HashMap::new();
|
||||
other.insert(String::from("variables2"), Complete);
|
||||
other.insert(String::from("functions2"), Complete);
|
||||
other.insert(String::from("if1"), Complete);
|
||||
other.insert(String::from("from_into"), None);
|
||||
other.insert(String::from("try_from_into"), None);
|
||||
|
||||
vec![map, other]
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
### Strings
|
||||
# Strings
|
||||
|
||||
Rust has two string types, a string slice (`&str`) and an owned string (`String`).
|
||||
We're not going to dictate when you should use which one, but we'll show you how
|
||||
to identify and create them, as well as use them.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Strings](https://doc.rust-lang.org/book/ch08-02-strings.html)
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// Make me compile without changing the function signature!
|
||||
// Execute `rustlings hint strings1` for hints ;)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let answer = current_favorite_color();
|
||||
println!("My current favorite color is {}", answer);
|
||||
}
|
||||
|
||||
fn current_favorite_color() -> String {
|
||||
"blue"
|
||||
// .to_string uses fmt trait
|
||||
// .to_owned works too
|
||||
"blue".to_owned()
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// Make me compile without changing the function signature!
|
||||
// Execute `rustlings hint strings2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let word = String::from("green"); // Try not changing this line :)
|
||||
if is_a_color_word(word) {
|
||||
|
@ -13,6 +11,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_a_color_word(attempt: &str) -> bool {
|
||||
fn is_a_color_word(attempt: String) -> bool {
|
||||
attempt == "green" || attempt == "blue" || attempt == "red"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
### Structs
|
||||
# Structs
|
||||
|
||||
Rust has three struct types: a classic c struct, a tuple struct, and a unit struct.
|
||||
Rust has three struct types: a classic C struct, a tuple struct, and a unit struct.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [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)
|
||||
- [Method Syntax](https://doc.rust-lang.org/book/ch05-03-method-syntax.html)
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
// structs1.rs
|
||||
// Address all the TODOs to make the tests pass!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
struct ColorClassicStruct {
|
||||
// TODO: Something goes here
|
||||
name: String,
|
||||
hex: String
|
||||
}
|
||||
|
||||
struct ColorTupleStruct(/* TODO: Something goes here */);
|
||||
struct ColorTupleStruct(String, String);
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UnitStruct;
|
||||
|
@ -19,8 +18,10 @@ mod tests {
|
|||
#[test]
|
||||
fn classic_c_structs() {
|
||||
// TODO: Instantiate a classic c struct!
|
||||
// let green =
|
||||
|
||||
let green = ColorClassicStruct {
|
||||
name: String::from("green"),
|
||||
hex: String::from("#00FF00")
|
||||
};
|
||||
assert_eq!(green.name, "green");
|
||||
assert_eq!(green.hex, "#00FF00");
|
||||
}
|
||||
|
@ -28,7 +29,7 @@ mod tests {
|
|||
#[test]
|
||||
fn tuple_structs() {
|
||||
// TODO: Instantiate a tuple struct!
|
||||
// let green =
|
||||
let green = ColorTupleStruct("green".to_string(),"#00FF00".to_string());
|
||||
|
||||
assert_eq!(green.0, "green");
|
||||
assert_eq!(green.1, "#00FF00");
|
||||
|
@ -37,7 +38,7 @@ mod tests {
|
|||
#[test]
|
||||
fn unit_structs() {
|
||||
// TODO: Instantiate a unit struct!
|
||||
// let unit_struct =
|
||||
let unit_struct = UnitStruct;
|
||||
let message = format!("{:?}s are fun!", unit_struct);
|
||||
|
||||
assert_eq!(message, "UnitStructs are fun!");
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// structs2.rs
|
||||
// Address all the TODOs to make the tests pass!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Order {
|
||||
name: String,
|
||||
|
@ -34,7 +32,15 @@ mod tests {
|
|||
fn your_order() {
|
||||
let order_template = create_order_template();
|
||||
// TODO: Create your own order using the update syntax and template above!
|
||||
// let your_order =
|
||||
let your_order = Order {
|
||||
name: String::from("Hacker in Rust"),
|
||||
year: 2019,
|
||||
made_by_phone: false,
|
||||
made_by_mobile: false,
|
||||
made_by_email: true,
|
||||
item_number: 123,
|
||||
count: 1,
|
||||
};
|
||||
assert_eq!(your_order.name, "Hacker in Rust");
|
||||
assert_eq!(your_order.year, order_template.year);
|
||||
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// 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`
|
||||
// Structs contain data, but 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 {
|
||||
|
@ -15,18 +15,30 @@ struct Package {
|
|||
impl Package {
|
||||
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
||||
if weight_in_grams <= 0 {
|
||||
// Something goes here...
|
||||
panic!("Weight is in negative value.");
|
||||
} else {
|
||||
return Package {sender_country, recipient_country, weight_in_grams};
|
||||
return Package {
|
||||
sender_country,
|
||||
recipient_country,
|
||||
weight_in_grams,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn is_international(&self) -> ??? {
|
||||
// Something goes here...
|
||||
fn is_international(&self) -> bool {
|
||||
if self.sender_country != self.recipient_country {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn get_fees(&self, cents_per_kg: i32) -> ??? {
|
||||
// Something goes here... (beware of grams to kg conversion)
|
||||
fn get_fees(&self, cents_per_gram: i32) -> i32 {
|
||||
if cents_per_gram <= 0 {
|
||||
panic!("We don't pay people, do we?");
|
||||
} else {
|
||||
cents_per_gram * self.weight_in_grams
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,21 +59,31 @@ mod tests {
|
|||
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 create_local_package() {
|
||||
let sender_country = String::from("Canada");
|
||||
let recipient_country = sender_country.clone();
|
||||
|
||||
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_kg = ???;
|
||||
|
||||
let cents_per_gram = 3;
|
||||
|
||||
let package = Package::new(sender_country, recipient_country, 1500);
|
||||
|
||||
assert_eq!(package.get_fees(cents_per_kg), 4500);
|
||||
|
||||
assert_eq!(package.get_fees(cents_per_gram), 4500);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### Tests
|
||||
# Tests
|
||||
|
||||
Going out of order from the book to cover tests -- many of the following exercises will ask you to make tests pass!
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Writing Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html)
|
||||
|
|
|
@ -18,4 +18,9 @@ mod tests {
|
|||
fn is_true_when_even() {
|
||||
assert!();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_false_when_odd() {
|
||||
assert!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,9 @@
|
|||
For this exercise check out the [Dining Philosophers example](https://doc.rust-lang.org/1.4.0/book/dining-philosophers.html) and the chapter [Concurrency](https://doc.rust-lang.org/book/ch16-01-threads.html) of the Rust Book.
|
||||
# Threads
|
||||
|
||||
In most current operating systems, an executed program’s code is run in a process, and the operating system manages multiple processes at once.
|
||||
Within your program, you can also have independent parts that run simultaneously. The features that run these independent parts are called threads.
|
||||
|
||||
## Further information
|
||||
|
||||
- [Dining Philosophers example](https://doc.rust-lang.org/1.4.0/book/dining-philosophers.html)
|
||||
- [Using Threads to Run Code Simultaneously](https://doc.rust-lang.org/book/ch16-01-threads.html)
|
||||
|
|
|
@ -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
|
||||
// The idea is the thread spawned on line 22 is completing jobs while the main thread is
|
||||
// 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 :)
|
||||
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
### Traits
|
||||
# Traits
|
||||
|
||||
A trait is a collection of methods.
|
||||
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 `{:?}`).
|
||||
- `Clone` (the `clone` method)
|
||||
- `Display` (which allows formatted display via `{}`)
|
||||
- `Debug` (which allows formatted display via `{:?}`)
|
||||
|
||||
Because traits indicate shared behavior between data types, they are useful when writing generics.
|
||||
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html)
|
||||
- [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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
### Variables
|
||||
# Variables
|
||||
|
||||
Here you'll learn about simple variables.
|
||||
In Rust, variables are immutable by default.
|
||||
When a variable is immutable, once a value is bound to a name, you can’t change that value.
|
||||
You can make them mutable by adding mut in front of the variable name.
|
||||
|
||||
#### Book Sections
|
||||
## Further information
|
||||
|
||||
- [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html)
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
// even after you already figured it out. If you got everything working and
|
||||
// feel ready for the next exercise, remove the `I AM NOT DONE` comment below.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
x = 5;
|
||||
let x = 5;
|
||||
println!("x has the value {}", x);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
// variables2.rs
|
||||
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let x;
|
||||
let x = 10;
|
||||
if x == 10 {
|
||||
println!("Ten!");
|
||||
} else {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
// variables3.rs
|
||||
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let x = 3;
|
||||
let mut x = 3;
|
||||
println!("Number {}", x);
|
||||
x = 5; // don't change this line
|
||||
println!("Number {}", x);
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
// variables4.rs
|
||||
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let x: i32;
|
||||
let mut x: i32;
|
||||
x = 512;
|
||||
println!("Number {}", x);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
// variables5.rs
|
||||
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let number = "3"; // don't change this line
|
||||
println!("Number {}", number);
|
||||
number = 3;
|
||||
println!("Number {}", number);
|
||||
let number = "T-H-R-E-E";
|
||||
println!("Spell a Number : {}", number);
|
||||
let number = 3;
|
||||
println!("Number plus two is : {}", number + 2);
|
||||
}
|
||||
|
|
|
@ -1,9 +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;
|
||||
// consts have to have strict data type definition
|
||||
// otherwise they won't work
|
||||
const NUMBER: i32 = 3;
|
||||
fn main() {
|
||||
println!("Number {}", NUMBER);
|
||||
}
|
||||
|
|
|
@ -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'"
|
||||
|
|
|
@ -87,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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::fs::{self, remove_file, File};
|
||||
use std::io::Read;
|
||||
|
@ -11,14 +12,19 @@ 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 to this process
|
||||
// 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)]
|
||||
#[derive(Deserialize, Copy, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Mode {
|
||||
// Indicates that the exercise should be compiled as a binary
|
||||
|
@ -36,7 +42,7 @@ pub struct ExerciseList {
|
|||
|
||||
// A representation of a rustlings exercise.
|
||||
// This is deserialized from the accompanying info.toml file
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Exercise {
|
||||
// Name of the exercise
|
||||
pub name: String,
|
||||
|
@ -121,8 +127,12 @@ 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.");
|
||||
let cargo_toml_error_msg = if env::var("NO_EMOJI").is_ok() {
|
||||
"Failed to write Clippy Cargo.toml file."
|
||||
} else {
|
||||
"Failed to write 📎 Clippy 📎 Cargo.toml file."
|
||||
};
|
||||
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml).expect(cargo_toml_error_msg);
|
||||
// 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
|
||||
|
@ -167,9 +177,10 @@ path = "{}.rs""#,
|
|||
fn run(&self) -> Result<ExerciseOutput, ExerciseOutput> {
|
||||
let arg = match self.mode {
|
||||
Mode::Test => "--show-output",
|
||||
_ => ""
|
||||
_ => "",
|
||||
};
|
||||
let cmd = Command::new(&temp_file()).arg(arg)
|
||||
let cmd = Command::new(&temp_file())
|
||||
.arg(arg)
|
||||
.output()
|
||||
.expect("Failed to run 'run' command");
|
||||
|
||||
|
@ -226,6 +237,16 @@ path = "{}.rs""#,
|
|||
|
||||
State::Pending(context)
|
||||
}
|
||||
|
||||
// Check that the exercise looks to be solved using self.state()
|
||||
// This is not the best way to check since
|
||||
// the user can just remove the "I AM NOT DONE" string from the file
|
||||
// without actually having solved anything.
|
||||
// The only other way to truly check this would to compile and run
|
||||
// the exercise; which would be both costly and counterintuitive
|
||||
pub fn looks_done(&self) -> bool {
|
||||
self.state() == State::Done
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Exercise {
|
||||
|
@ -314,7 +335,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_exercise_with_output() {
|
||||
let exercise = Exercise {
|
||||
name: "finished_exercise".into(),
|
||||
name: "exercise_with_output".into(),
|
||||
path: PathBuf::from("tests/fixture/success/testSuccess.rs"),
|
||||
mode: Mode::Test,
|
||||
hint: String::new(),
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue