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_.
|
||||
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).
|
||||
>
|
||||
|
@ -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?
|
||||
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
|
||||
|
||||
|
|
|
@ -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,
|
||||
position: Point,
|
||||
message: String,
|
||||
// RGB color composed of red, green and blue.
|
||||
color: (u8, u8, u8),
|
||||
quit: bool,
|
||||
}
|
||||
|
@ -30,8 +31,8 @@ impl State {
|
|||
self.message = s;
|
||||
}
|
||||
|
||||
fn change_color(&mut self, color: (u8, u8, u8)) {
|
||||
self.color = color;
|
||||
fn change_color(&mut self, red: u8, green: u8, blue: u8) {
|
||||
self.color = (red, green, blue);
|
||||
}
|
||||
|
||||
fn quit(&mut self) {
|
||||
|
@ -39,9 +40,8 @@ impl State {
|
|||
}
|
||||
|
||||
fn process(&mut self, message: Message) {
|
||||
// TODO: Create a match expression to process the different message variants.
|
||||
// Remember: When passing a tuple as a function argument, you'll need extra parentheses:
|
||||
// e.g. `foo((t, u, p, l, e))`
|
||||
// TODO: Create a match expression to process the different message
|
||||
// variants using the methods defined above.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,9 @@ mod tests {
|
|||
#[test]
|
||||
fn owned_no_mutation() {
|
||||
// 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
|
||||
// still owned because it was never borrowed or mutated.
|
||||
// case, no mutation occurs (all numbers are already absolute) and thus
|
||||
// also no clone. But the result is still owned because it was never
|
||||
// borrowed or mutated.
|
||||
let vec = vec![0, 1, 2];
|
||||
let mut input = Cow::from(vec);
|
||||
abs_all(&mut input);
|
||||
|
@ -56,9 +57,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn owned_mutation() {
|
||||
// Of course this is also the case if a mutation does occur. In this
|
||||
// case, the call to `to_mut()` in the `abs_all` function returns a
|
||||
// reference to the same data as before.
|
||||
// Of course this is also the case if a mutation does occur (not all
|
||||
// numbers are absolute). In this case, the call to `to_mut()` in the
|
||||
// `abs_all` function returns a reference to the same data as before.
|
||||
let vec = vec![-1, 0, 1];
|
||||
let mut input = Cow::from(vec);
|
||||
abs_all(&mut input);
|
||||
|
|
|
@ -34,8 +34,8 @@ impl State {
|
|||
self.message = s;
|
||||
}
|
||||
|
||||
fn change_color(&mut self, color: (u8, u8, u8)) {
|
||||
self.color = color;
|
||||
fn change_color(&mut self, red: u8, green: u8, blue: u8) {
|
||||
self.color = (red, green, blue);
|
||||
}
|
||||
|
||||
fn quit(&mut self) {
|
||||
|
@ -47,7 +47,7 @@ impl State {
|
|||
Message::Resize { width, height } => self.resize(width, height),
|
||||
Message::Move(point) => self.move_position(point),
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,8 +45,9 @@ mod tests {
|
|||
#[test]
|
||||
fn owned_no_mutation() {
|
||||
// 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
|
||||
// still owned because it was never borrowed or mutated.
|
||||
// case, no mutation occurs (all numbers are already absolute) and thus
|
||||
// also no clone. But the result is still owned because it was never
|
||||
// borrowed or mutated.
|
||||
let vec = vec![0, 1, 2];
|
||||
let mut input = Cow::from(vec);
|
||||
abs_all(&mut input);
|
||||
|
@ -56,9 +57,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn owned_mutation() {
|
||||
// Of course this is also the case if a mutation does occur. In this
|
||||
// case, the call to `to_mut()` in the `abs_all` function returns a
|
||||
// reference to the same data as before.
|
||||
// Of course this is also the case if a mutation does occur (not all
|
||||
// numbers are absolute). In this case, the call to `to_mut()` in the
|
||||
// `abs_all` function returns a reference to the same data as before.
|
||||
let vec = vec![-1, 0, 1];
|
||||
let mut input = Cow::from(vec);
|
||||
abs_all(&mut input);
|
||||
|
|
|
@ -24,17 +24,12 @@ mod my_module {
|
|||
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
||||
let mut output = Vec::new();
|
||||
|
||||
for (mut string, command) in input {
|
||||
for (string, command) in input {
|
||||
// Create the new string.
|
||||
let new_string = match command {
|
||||
Command::Uppercase => string.to_uppercase(),
|
||||
Command::Trim => string.trim().to_string(),
|
||||
Command::Append(n) => {
|
||||
for _ in 0..n {
|
||||
string += "bar";
|
||||
}
|
||||
string
|
||||
}
|
||||
Command::Append(n) => string + &"bar".repeat(n),
|
||||
};
|
||||
|
||||
// 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> {
|
||||
input
|
||||
.into_iter()
|
||||
.map(|(mut string, command)| match command {
|
||||
.map(|(string, command)| match command {
|
||||
Command::Uppercase => string.to_uppercase(),
|
||||
Command::Trim => string.trim().to_string(),
|
||||
Command::Append(n) => {
|
||||
for _ in 0..n {
|
||||
string += "bar";
|
||||
}
|
||||
string
|
||||
}
|
||||
Command::Append(n) => string + &"bar".repeat(n),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -403,6 +403,9 @@ impl AppState {
|
|||
writeln!(writer, "{}", "ok".green())?;
|
||||
}
|
||||
|
||||
// Write that the last exercise is done.
|
||||
self.write()?;
|
||||
|
||||
clear_terminal(writer)?;
|
||||
writer.write_all(FENISH_LINE.as_bytes())?;
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ const README: &str = "# Rustlings 🦀
|
|||
|
||||
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(())
|
||||
}
|
||||
|
||||
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.
|
||||
Please follow the instructions in the README:
|
||||
Please follow the instructions in `README.md`:
|
||||
https://github.com/rust-lang/rustlings#getting-started";
|
||||
|
||||
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.";
|
||||
|
|
Loading…
Reference in a new issue