mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-28 00:00:03 +03:00
Compare commits
9 commits
981a4778a9
...
0f4cb94cfe
Author | SHA1 | Date | |
---|---|---|---|
0f4cb94cfe | |||
6469e9734b | |||
5372caefb3 | |||
9d7b973a62 | |||
a5f221aa39 | |||
e764b75aef | |||
708cfef3f7 | |||
01b8432d58 | |||
9b5b652c71 |
|
@ -19,7 +19,7 @@ It contains code examples and exercises similar to Rustlings, but online.
|
||||||
|
|
||||||
Before installing Rustlings, you need to have _Rust installed_.
|
Before installing Rustlings, you need to have _Rust installed_.
|
||||||
Visit [www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) for further instructions on installing Rust.
|
Visit [www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) for further instructions on installing Rust.
|
||||||
This'll also install _Cargo_, Rust's package/project manager.
|
This will also install _Cargo_, Rust's package/project manager.
|
||||||
|
|
||||||
> 🐧 If you're on Linux, make sure you've installed `gcc` (for a linker).
|
> 🐧 If you're on Linux, make sure you've installed `gcc` (for a linker).
|
||||||
>
|
>
|
||||||
|
@ -124,7 +124,7 @@ Continue practicing your Rust skills by building your own projects, contributing
|
||||||
|
|
||||||
Do you want to create your own set of Rustlings exercises to focus on some specific topic?
|
Do you want to create your own set of Rustlings exercises to focus on some specific topic?
|
||||||
Or do you want to translate the original Rustlings exercises?
|
Or do you want to translate the original Rustlings exercises?
|
||||||
Then follow the link to the guide about [third-party exercises](THIRD_PARTY_EXERCISES.md)!
|
Then follow the link to the guide about [third-party exercises](https://github.com/rust-lang/rustlings/blob/main/THIRD_PARTY_EXERCISES.md)!
|
||||||
|
|
||||||
## Uninstalling Rustlings
|
## Uninstalling Rustlings
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
This file is used to check if the user tries to run Rustlings in the repository (the method before v6)
|
This file is used to check if the user tries to run Rustlings in the repository (the method before version 6)
|
||||||
|
|
|
@ -12,6 +12,7 @@ struct State {
|
||||||
height: u64,
|
height: u64,
|
||||||
position: Point,
|
position: Point,
|
||||||
message: String,
|
message: String,
|
||||||
|
// RGB color composed of red, green and blue.
|
||||||
color: (u8, u8, u8),
|
color: (u8, u8, u8),
|
||||||
quit: bool,
|
quit: bool,
|
||||||
}
|
}
|
||||||
|
@ -30,8 +31,8 @@ impl State {
|
||||||
self.message = s;
|
self.message = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_color(&mut self, color: (u8, u8, u8)) {
|
fn change_color(&mut self, red: u8, green: u8, blue: u8) {
|
||||||
self.color = color;
|
self.color = (red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit(&mut self) {
|
fn quit(&mut self) {
|
||||||
|
@ -39,9 +40,8 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&mut self, message: Message) {
|
fn process(&mut self, message: Message) {
|
||||||
// TODO: Create a match expression to process the different message variants.
|
// TODO: Create a match expression to process the different message
|
||||||
// Remember: When passing a tuple as a function argument, you'll need extra parentheses:
|
// variants using the methods defined above.
|
||||||
// e.g. `foo((t, u, p, l, e))`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_no_mutation() {
|
fn owned_no_mutation() {
|
||||||
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
||||||
// case, no mutation occurs and thus also no clone. But the result is
|
// case, no mutation occurs (all numbers are already absolute) and thus
|
||||||
// still owned because it was never borrowed or mutated.
|
// also no clone. But the result is still owned because it was never
|
||||||
|
// borrowed or mutated.
|
||||||
let vec = vec![0, 1, 2];
|
let vec = vec![0, 1, 2];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
@ -56,9 +57,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_mutation() {
|
fn owned_mutation() {
|
||||||
// Of course this is also the case if a mutation does occur. In this
|
// Of course this is also the case if a mutation does occur (not all
|
||||||
// case, the call to `to_mut()` in the `abs_all` function returns a
|
// numbers are absolute). In this case, the call to `to_mut()` in the
|
||||||
// reference to the same data as before.
|
// `abs_all` function returns a reference to the same data as before.
|
||||||
let vec = vec![-1, 0, 1];
|
let vec = vec![-1, 0, 1];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
|
|
@ -34,8 +34,8 @@ impl State {
|
||||||
self.message = s;
|
self.message = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_color(&mut self, color: (u8, u8, u8)) {
|
fn change_color(&mut self, red: u8, green: u8, blue: u8) {
|
||||||
self.color = color;
|
self.color = (red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit(&mut self) {
|
fn quit(&mut self) {
|
||||||
|
@ -47,7 +47,7 @@ impl State {
|
||||||
Message::Resize { width, height } => self.resize(width, height),
|
Message::Resize { width, height } => self.resize(width, height),
|
||||||
Message::Move(point) => self.move_position(point),
|
Message::Move(point) => self.move_position(point),
|
||||||
Message::Echo(s) => self.echo(s),
|
Message::Echo(s) => self.echo(s),
|
||||||
Message::ChangeColor(r, g, b) => self.change_color((r, g, b)),
|
Message::ChangeColor(r, g, b) => self.change_color(r, g, b),
|
||||||
Message::Quit => self.quit(),
|
Message::Quit => self.quit(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_no_mutation() {
|
fn owned_no_mutation() {
|
||||||
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
||||||
// case, no mutation occurs and thus also no clone. But the result is
|
// case, no mutation occurs (all numbers are already absolute) and thus
|
||||||
// still owned because it was never borrowed or mutated.
|
// also no clone. But the result is still owned because it was never
|
||||||
|
// borrowed or mutated.
|
||||||
let vec = vec![0, 1, 2];
|
let vec = vec![0, 1, 2];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
@ -56,9 +57,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_mutation() {
|
fn owned_mutation() {
|
||||||
// Of course this is also the case if a mutation does occur. In this
|
// Of course this is also the case if a mutation does occur (not all
|
||||||
// case, the call to `to_mut()` in the `abs_all` function returns a
|
// numbers are absolute). In this case, the call to `to_mut()` in the
|
||||||
// reference to the same data as before.
|
// `abs_all` function returns a reference to the same data as before.
|
||||||
let vec = vec![-1, 0, 1];
|
let vec = vec![-1, 0, 1];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
|
|
@ -24,17 +24,12 @@ mod my_module {
|
||||||
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
|
|
||||||
for (mut string, command) in input {
|
for (string, command) in input {
|
||||||
// Create the new string.
|
// Create the new string.
|
||||||
let new_string = match command {
|
let new_string = match command {
|
||||||
Command::Uppercase => string.to_uppercase(),
|
Command::Uppercase => string.to_uppercase(),
|
||||||
Command::Trim => string.trim().to_string(),
|
Command::Trim => string.trim().to_string(),
|
||||||
Command::Append(n) => {
|
Command::Append(n) => string + &"bar".repeat(n),
|
||||||
for _ in 0..n {
|
|
||||||
string += "bar";
|
|
||||||
}
|
|
||||||
string
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Push the new string to the output vector.
|
// Push the new string to the output vector.
|
||||||
|
@ -49,15 +44,10 @@ mod my_module {
|
||||||
pub fn transformer_iter(input: Vec<(String, Command)>) -> Vec<String> {
|
pub fn transformer_iter(input: Vec<(String, Command)>) -> Vec<String> {
|
||||||
input
|
input
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(mut string, command)| match command {
|
.map(|(string, command)| match command {
|
||||||
Command::Uppercase => string.to_uppercase(),
|
Command::Uppercase => string.to_uppercase(),
|
||||||
Command::Trim => string.trim().to_string(),
|
Command::Trim => string.trim().to_string(),
|
||||||
Command::Append(n) => {
|
Command::Append(n) => string + &"bar".repeat(n),
|
||||||
for _ in 0..n {
|
|
||||||
string += "bar";
|
|
||||||
}
|
|
||||||
string
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,6 +403,9 @@ impl AppState {
|
||||||
writeln!(writer, "{}", "ok".green())?;
|
writeln!(writer, "{}", "ok".green())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write that the last exercise is done.
|
||||||
|
self.write()?;
|
||||||
|
|
||||||
clear_terminal(writer)?;
|
clear_terminal(writer)?;
|
||||||
writer.write_all(FENISH_LINE.as_bytes())?;
|
writer.write_all(FENISH_LINE.as_bytes())?;
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ const README: &str = "# Rustlings 🦀
|
||||||
|
|
||||||
Welcome to these third-party Rustlings exercises 😃
|
Welcome to these third-party Rustlings exercises 😃
|
||||||
|
|
||||||
First, [install Rustlings using the official instructions in the README of the Rustlings project](https://github.com/rust-lang/rustlings) ✅
|
First, [install Rustlings using the official instructions](https://github.com/rust-lang/rustlings) ✅
|
||||||
|
|
||||||
Then, open your terminal in this directory and run `rustlings` to get started with the exercises 🚀
|
Then, clone this repository, open a terminal in this directory and run `rustlings` to get started with the exercises 🚀
|
||||||
";
|
";
|
||||||
|
|
|
@ -197,9 +197,10 @@ fn main() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
const OLD_METHOD_ERR: &str = "You are trying to run Rustlings using the old method before v6.
|
const OLD_METHOD_ERR: &str =
|
||||||
|
"You are trying to run Rustlings using the old method before version 6.
|
||||||
The new method doesn't include cloning the Rustlings' repository.
|
The new method doesn't include cloning the Rustlings' repository.
|
||||||
Please follow the instructions in the README:
|
Please follow the instructions in `README.md`:
|
||||||
https://github.com/rust-lang/rustlings#getting-started";
|
https://github.com/rust-lang/rustlings#getting-started";
|
||||||
|
|
||||||
const FORMAT_VERSION_HIGHER_ERR: &str =
|
const FORMAT_VERSION_HIGHER_ERR: &str =
|
||||||
|
@ -216,5 +217,5 @@ const PRE_INIT_MSG: &str = r"
|
||||||
|_| \__,_|___/\__|_|_|_| |_|\__, |___/
|
|_| \__,_|___/\__|_|_|_| |_|\__, |___/
|
||||||
|___/
|
|___/
|
||||||
|
|
||||||
The `exercises` directory wasn't found in the current directory.
|
The `exercises/` directory couldn't be found in the current directory.
|
||||||
If you are just starting with Rustlings, run the command `rustlings init` to initialize it.";
|
If you are just starting with Rustlings, run the command `rustlings init` to initialize it.";
|
||||||
|
|
Loading…
Reference in a new issue