✔ The fundamentals of Rust.
✔ The standard Rust libraries.
✔ Data structures with Rust.
All the required information to install dependencies can be found in SETUP.md.
💡 We recommend you to follow the Tour of Rust for this workshop.
❗ We strongly advise you to use the resources given for this exercise.
For the first exercise, we simply ask you to write Hello world!
in your terminal when you run your program.
To do this, create a file main.rs
in a folder called src
.
💡 Rust file has
rs
extension.
💡 Now, that you have created a file
main.rs
, you can use other files. To use them in yourmain.rs
you have to integrate the module with the keywordmod
(read more)
❗ We strongly advise you to use the resources given for this exercise.
For the second exercise, you have to create a function that takes as parameter a string word
.
Create a file palindrome.rs
for this new function.
This function must return true if the word given in parameter is a palindrome and false in the opposite case.
💡 To easily test your functions during this workshop, we advise you to look at this tool.
assert_eq
❗ We strongly advise you to use the resources given for this exercise.
Create a file fibonacci.rs
for this new function.
For the third exercise, create a function that takes one parameter:
- A number
max
with typeusize
that represent the number of element to compute.
You must now display the sequence of Fibonacci from the number of starts to the maximum value.
Here is a small example of the beginning of the Fibonacci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
In this exercise, you will transform vectors into a linked list.
To do this, you will create a file to_list.rs
.
First, create a linked_list
structure with the following attributes:
value: i32
next
which has the structure type.
💡 It's up to you to figure out how to initialize the structure to make a linked list.
In a second step, create a vector vector
which will be transformed into a linked list.
As you will have understood, the objective of the exercise is to transform a vector into a linked list.
To do this, create a function to_list
which takes vector
as parameter and returns the list.
❗ We strongly advise you to use the resources given for this exercise.
Let's go further now!
The objective of this fifth exercise is to create a simplifying calculator.
Create a file calculator.rs
for this new function.
To do this, you have to make a calculator that can do:
Addition
Multiplication
Division
Subtraction
between two values that must be retrieved one after the other from the user's input.
💡 Pay attention to your error handling !
Display the result of the calculation in your terminal.
❗ We strongly advise you to use the resources given for this exercise.
The serious stuff begins!
This exercise is inspired by the Pig Latin
concept, so feel free to look at the original version to help you.
Create a file pig_latin.rs
for this new function.
Get a string as parameter, from this word you have to apply or not the following rules:
-
If the word starts with a vowel, it doesn't matter. You just need to add a suffix
-hay
to your word. -
If the word starts with a consonant, you must take the first letter of the word and place it in the first position of the suffix.
💡 To help you visualize the exercise, here are some examples:
"PoC" --> "oC-Pay"
"Epitech" --> "Epitech-hay"
"Bumblebee" --> "umblebee-Bay"
"Although" --> "Although-hay"
Well done! 🎉
Now that you can apply this to words, why not apply it to sentences?
As you can see, try to do the same thing, but for whole sentences.
To do this reuse the same function, but create a loop in your function.
💡 Here are some examples too:
"Live as if you were to die tomorrow. Learn as if you were to live forever."
-->
"ive-Lay as-hay if-hay you-hay ere-way o-tay ie-day omorrow-tay. earn-Lay as-hay if-hay you-hay ere-way o-tay ive-lay orever-fay."
"A problem without a solution is a poorly stated problem"
-->
"A-hay roblem-pay ithout-way a-hay olution-say is-hay a-hay oorly-pay tated-say roblem-pay."
Here are some bonus ideas if you want to venture further into the Rust adventure! 💪
- Why not remake your Bistro-matic in Rust?
Yoel EDERY |
Nicolas HEUDE |
---|
🚀 Don't hesitate to follow us on our different networks, and put a star 🌟 on
PoC's
repositories.