mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 05:09:19 +00:00
Merge branch 'main' into all
This commit is contained in:
commit
023aa68440
@ -1002,6 +1002,78 @@
|
|||||||
"contributions": [
|
"contributions": [
|
||||||
"content"
|
"content"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "EmisonLu",
|
||||||
|
"name": "Zhenghao Lu",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/54395432?v=4",
|
||||||
|
"profile": "https://github.com/EmisonLu",
|
||||||
|
"contributions": [
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "fredr",
|
||||||
|
"name": "Fredrik Enestad",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/762956?v=4",
|
||||||
|
"profile": "https://soundtrackyourbrand.com",
|
||||||
|
"contributions": [
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "xuesongbj",
|
||||||
|
"name": "xuesong",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/18476085?v=4",
|
||||||
|
"profile": "http://xuesong.pydevops.com",
|
||||||
|
"contributions": [
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "MpdWalsh",
|
||||||
|
"name": "Michael Walsh",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/48160144?v=4",
|
||||||
|
"profile": "https://github.com/MpdWalsh",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "alirezaghey",
|
||||||
|
"name": "alirezaghey",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/26653424?v=4",
|
||||||
|
"profile": "https://github.com/alirezaghey",
|
||||||
|
"contributions": [
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "frvannes16",
|
||||||
|
"name": "Franklin van Nes",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/3188475?v=4",
|
||||||
|
"profile": "https://github.com/frvannes16",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "nekonako",
|
||||||
|
"name": "nekonako",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/46141275?v=4",
|
||||||
|
"profile": "https://nekonako.github.io",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "tan-zx",
|
||||||
|
"name": "ZX",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/67887489?v=4",
|
||||||
|
"profile": "https://github.com/tan-zx",
|
||||||
|
"contributions": [
|
||||||
|
"content"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 8,
|
"contributorsPerLine": 8,
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
name = "rustlings"
|
name = "rustlings"
|
||||||
version = "4.6.0"
|
version = "4.6.0"
|
||||||
authors = ["anastasie <ana@ana.st>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
|
authors = ["anastasie <ana@ana.st>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argh = "0.1.4"
|
argh = "0.1.4"
|
||||||
|
|||||||
12
README.md
12
README.md
@ -1,5 +1,5 @@
|
|||||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||||
[](#contributors-)
|
[](#contributors-)
|
||||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||||
|
|
||||||
# rustlings 🦀❤️
|
# rustlings 🦀❤️
|
||||||
@ -312,6 +312,16 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<td align="center"><a href="https://github.com/Millione"><img src="https://avatars.githubusercontent.com/u/38575932?v=4?s=100" width="100px;" alt=""/><br /><sub><b>LIU JIE</b></sub></a><br /><a href="#content-Millione" title="Content">🖋</a></td>
|
<td align="center"><a href="https://github.com/Millione"><img src="https://avatars.githubusercontent.com/u/38575932?v=4?s=100" width="100px;" alt=""/><br /><sub><b>LIU JIE</b></sub></a><br /><a href="#content-Millione" title="Content">🖋</a></td>
|
||||||
<td align="center"><a href="https://github.com/abusch"><img src="https://avatars.githubusercontent.com/u/506344?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antoine Büsch</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=abusch" title="Code">💻</a></td>
|
<td align="center"><a href="https://github.com/abusch"><img src="https://avatars.githubusercontent.com/u/506344?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antoine Büsch</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=abusch" title="Code">💻</a></td>
|
||||||
<td align="center"><a href="https://frogtd.com/"><img src="https://avatars.githubusercontent.com/u/31412003?v=4?s=100" width="100px;" alt=""/><br /><sub><b>frogtd</b></sub></a><br /><a href="#content-frogtd" title="Content">🖋</a></td>
|
<td align="center"><a href="https://frogtd.com/"><img src="https://avatars.githubusercontent.com/u/31412003?v=4?s=100" width="100px;" alt=""/><br /><sub><b>frogtd</b></sub></a><br /><a href="#content-frogtd" title="Content">🖋</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/EmisonLu"><img src="https://avatars.githubusercontent.com/u/54395432?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Zhenghao Lu</b></sub></a><br /><a href="#content-EmisonLu" title="Content">🖋</a></td>
|
||||||
|
<td align="center"><a href="https://soundtrackyourbrand.com"><img src="https://avatars.githubusercontent.com/u/762956?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fredrik Enestad</b></sub></a><br /><a href="#content-fredr" title="Content">🖋</a></td>
|
||||||
|
<td align="center"><a href="http://xuesong.pydevops.com"><img src="https://avatars.githubusercontent.com/u/18476085?v=4?s=100" width="100px;" alt=""/><br /><sub><b>xuesong</b></sub></a><br /><a href="#content-xuesongbj" title="Content">🖋</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/MpdWalsh"><img src="https://avatars.githubusercontent.com/u/48160144?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Walsh</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=MpdWalsh" title="Code">💻</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center"><a href="https://github.com/alirezaghey"><img src="https://avatars.githubusercontent.com/u/26653424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>alirezaghey</b></sub></a><br /><a href="#content-alirezaghey" title="Content">🖋</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/frvannes16"><img src="https://avatars.githubusercontent.com/u/3188475?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Franklin van Nes</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=frvannes16" title="Code">💻</a></td>
|
||||||
|
<td align="center"><a href="https://nekonako.github.io"><img src="https://avatars.githubusercontent.com/u/46141275?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nekonako</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=nekonako" title="Code">💻</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/tan-zx"><img src="https://avatars.githubusercontent.com/u/67887489?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ZX</b></sub></a><br /><a href="#content-tan-zx" title="Content">🖋</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@ -8,10 +8,16 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
use std::f32;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 1.2331f64;
|
let pi = 3.14f32;
|
||||||
let y = 1.2332f64;
|
let radius = 5.00f32;
|
||||||
if y != x {
|
|
||||||
println!("Success!");
|
let area = pi * f32::powi(radius, 2);
|
||||||
}
|
|
||||||
|
println!(
|
||||||
|
"The area of a circle with radius {:.2} is {:.5}!",
|
||||||
|
radius, area
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// move_semantics5.rs
|
// move_semantics5.rs
|
||||||
// Make me compile only be reordering the lines in `main()`, but without
|
// Make me compile only by reordering the lines in `main()`, but without
|
||||||
// adding, changing or removing any of them.
|
// adding, changing or removing any of them.
|
||||||
// Execute `rustlings hint move_semantics5` for hints :)
|
// Execute `rustlings hint move_semantics5` for hints :)
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// This is a quiz for the following sections:
|
// This is a quiz for the following sections:
|
||||||
// - Variables
|
// - Variables
|
||||||
// - Functions
|
// - Functions
|
||||||
|
// - If
|
||||||
|
|
||||||
// Mary is buying apples. One apple usually costs 2 Rustbucks, but if you buy
|
// Mary is buying apples. One apple usually costs 2 Rustbucks, but if you buy
|
||||||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||||
|
|||||||
@ -19,11 +19,11 @@ impl Package {
|
|||||||
// Something goes here...
|
// Something goes here...
|
||||||
panic!("Weight of package is less than 0.");
|
panic!("Weight of package is less than 0.");
|
||||||
} else {
|
} else {
|
||||||
return Package {
|
Package {
|
||||||
sender_country,
|
sender_country,
|
||||||
recipient_country,
|
recipient_country,
|
||||||
weight_in_grams,
|
weight_in_grams,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,12 +34,12 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_FooBar() {
|
fn is_foo_bar() {
|
||||||
assert_eq!(String::from("Foo").append_bar(), String::from("FooBar"));
|
assert_eq!(String::from("Foo").append_bar(), String::from("FooBar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_BarBar() {
|
fn is_bar_bar() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from("").append_bar().append_bar(),
|
String::from("").append_bar().append_bar(),
|
||||||
String::from("BarBar")
|
String::from("BarBar")
|
||||||
|
|||||||
21
info.toml
21
info.toml
@ -114,8 +114,7 @@ path = "exercises/functions/functions5.rs"
|
|||||||
mode = "compile"
|
mode = "compile"
|
||||||
hint = """
|
hint = """
|
||||||
This is a really common error that can be fixed by removing one character.
|
This is a really common error that can be fixed by removing one character.
|
||||||
It happens because Rust distinguishes between expressions and statements: expressions return
|
It happens because Rust distinguishes between expressions and statements: expressions return a value based on their operand(s), and statements simply return a () type which behaves just like `void` in C/C++ language.
|
||||||
a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
|
|
||||||
We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
|
We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
|
||||||
They are not the same. There are two solutions:
|
They are not the same. There are two solutions:
|
||||||
1. Add a `return` ahead of `num * num;`
|
1. Add a `return` ahead of `num * num;`
|
||||||
@ -364,7 +363,7 @@ mode = "compile"
|
|||||||
hint = """
|
hint = """
|
||||||
The delicious_snacks module is trying to present an external interface that is
|
The delicious_snacks module is trying to present an external interface that is
|
||||||
different than its internal structure (the `fruits` and `veggies` modules and
|
different than its internal structure (the `fruits` and `veggies` modules and
|
||||||
associated constants). Complete the `use` statemants to fit the uses in main and
|
associated constants). Complete the `use` statements to fit the uses in main and
|
||||||
find the one keyword missing for both constants."""
|
find the one keyword missing for both constants."""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
@ -907,15 +906,15 @@ name = "clippy1"
|
|||||||
path = "exercises/clippy/clippy1.rs"
|
path = "exercises/clippy/clippy1.rs"
|
||||||
mode = "clippy"
|
mode = "clippy"
|
||||||
hint = """
|
hint = """
|
||||||
Not every floating point value can be represented exactly in binary values in
|
Rust stores the highest precision version of any long or inifinite precision
|
||||||
memory. Take a look at the description of
|
mathematical constants in the rust standard library.
|
||||||
https://doc.rust-lang.org/stable/std/primitive.f32.html
|
https://doc.rust-lang.org/stable/std/f32/consts/index.html
|
||||||
When using the binary compare operators with floating points you won't compare
|
|
||||||
the floating point values but the binary representation in memory. This is
|
We may be tempted to use our own approximations for certain mathematical constants,
|
||||||
usually not what you would like to do.
|
but clippy recognizes those imprecise mathematical constants as a source of
|
||||||
|
potential error.
|
||||||
See the suggestions of the clippy warning in compile output and use the
|
See the suggestions of the clippy warning in compile output and use the
|
||||||
machine epsilon value...
|
appropriate replacement constant from std::f32::consts..."""
|
||||||
https://doc.rust-lang.org/stable/std/primitive.f32.html#associatedconstant.EPSILON"""
|
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "clippy2"
|
name = "clippy2"
|
||||||
|
|||||||
@ -217,8 +217,7 @@ path = "{}.rs""#,
|
|||||||
let matched_line_index = source
|
let matched_line_index = source
|
||||||
.lines()
|
.lines()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, line)| if re.is_match(line) { Some(i) } else { None })
|
.find_map(|(i, line)| if re.is_match(line) { Some(i) } else { None })
|
||||||
.next()
|
|
||||||
.expect("This should not happen at all");
|
.expect("This should not happen at all");
|
||||||
|
|
||||||
let min_line = ((matched_line_index as i32) - (CONTEXT as i32)).max(0) as usize;
|
let min_line = ((matched_line_index as i32) - (CONTEXT as i32)).max(0) as usize;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user