mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Compare commits
7 commits
aed90be1cc
...
4b71f204be
Author | SHA1 | Date | |
---|---|---|---|
4b71f204be | |||
8d0aa11a35 | |||
e2674498c6 | |||
3200581d4d | |||
6afc4840b4 | |||
93aef73eb5 | |||
77b687d501 |
|
@ -2550,6 +2550,15 @@
|
||||||
"contributions": [
|
"contributions": [
|
||||||
"content"
|
"content"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "gerases",
|
||||||
|
"name": "gerases",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/8953623?v=4",
|
||||||
|
"profile": "https://github.com/gerases",
|
||||||
|
"contributions": [
|
||||||
|
"content"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 8,
|
"contributorsPerLine": 8,
|
||||||
|
|
|
@ -360,6 +360,9 @@ authors.
|
||||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/neuschaefer"><img src="https://avatars.githubusercontent.com/u/1021512?v=4?s=100" width="100px;" alt="J. Neuschäfer"/><br /><sub><b>J. Neuschäfer</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=neuschaefer" title="Code">💻</a></td>
|
<td align="center" valign="top" width="12.5%"><a href="https://github.com/neuschaefer"><img src="https://avatars.githubusercontent.com/u/1021512?v=4?s=100" width="100px;" alt="J. Neuschäfer"/><br /><sub><b>J. Neuschäfer</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=neuschaefer" title="Code">💻</a></td>
|
||||||
<td align="center" valign="top" width="12.5%"><a href="https://scooterhacking.org"><img src="https://avatars.githubusercontent.com/u/58905488?v=4?s=100" width="100px;" alt="Bastian Pedersen"/><br /><sub><b>Bastian Pedersen</b></sub></a><br /><a href="#content-bastianpedersen" title="Content">🖋</a></td>
|
<td align="center" valign="top" width="12.5%"><a href="https://scooterhacking.org"><img src="https://avatars.githubusercontent.com/u/58905488?v=4?s=100" width="100px;" alt="Bastian Pedersen"/><br /><sub><b>Bastian Pedersen</b></sub></a><br /><a href="#content-bastianpedersen" title="Content">🖋</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" width="12.5%"><a href="https://github.com/gerases"><img src="https://avatars.githubusercontent.com/u/8953623?v=4?s=100" width="100px;" alt="gerases"/><br /><sub><b>gerases</b></sub></a><br /><a href="#content-gerases" title="Content">🖋</a></td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ enum Message {
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{:?}", Message::Quit);
|
println!("{:?}", Message::Quit);
|
||||||
println!("{:?}", Message::Echo);
|
println!("{:?}", Message::Echo);
|
||||||
|
println!("{:?}", Message::Resize);
|
||||||
println!("{:?}", Message::Move);
|
println!("{:?}", Message::Move);
|
||||||
println!("{:?}", Message::ChangeColor);
|
println!("{:?}", Message::ChangeColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,12 @@ enum Message {
|
||||||
// TODO: define the different variants used below
|
// TODO: define the different variants used below
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Point {
|
||||||
|
x: u8,
|
||||||
|
y: u8,
|
||||||
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
fn call(&self) {
|
fn call(&self) {
|
||||||
println!("{:?}", self);
|
println!("{:?}", self);
|
||||||
|
@ -18,7 +24,8 @@ impl Message {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let messages = [
|
let messages = [
|
||||||
Message::Move { x: 10, y: 30 },
|
Message::Resize { w: 10, h: 30 },
|
||||||
|
Message::Move(Point { x: 10, y: 15 }),
|
||||||
Message::Echo(String::from("hello world")),
|
Message::Echo(String::from("hello world")),
|
||||||
Message::ChangeColor(200, 255, 255),
|
Message::ChangeColor(200, 255, 255),
|
||||||
Message::Quit,
|
Message::Quit,
|
||||||
|
|
|
@ -18,6 +18,8 @@ struct Point {
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
color: (u8, u8, u8),
|
color: (u8, u8, u8),
|
||||||
|
width: u8,
|
||||||
|
height: u8,
|
||||||
position: Point,
|
position: Point,
|
||||||
quit: bool,
|
quit: bool,
|
||||||
message: String,
|
message: String,
|
||||||
|
@ -36,6 +38,11 @@ impl State {
|
||||||
self.message = s
|
self.message = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resize(&mut self, w: u8, h: u8) {
|
||||||
|
self.width = w;
|
||||||
|
self.height = h;
|
||||||
|
}
|
||||||
|
|
||||||
fn move_position(&mut self, p: Point) {
|
fn move_position(&mut self, p: Point) {
|
||||||
self.position = p;
|
self.position = p;
|
||||||
}
|
}
|
||||||
|
@ -55,16 +62,21 @@ mod tests {
|
||||||
fn test_match_message_call() {
|
fn test_match_message_call() {
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
quit: false,
|
quit: false,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
position: Point { x: 0, y: 0 },
|
position: Point { x: 0, y: 0 },
|
||||||
color: (0, 0, 0),
|
color: (0, 0, 0),
|
||||||
message: "hello world".to_string(),
|
message: "hello world".to_string(),
|
||||||
};
|
};
|
||||||
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::Echo(String::from("Hello world!")));
|
||||||
|
state.process(Message::Resize { w: 10, h: 30 });
|
||||||
state.process(Message::Move(Point { x: 10, y: 15 }));
|
state.process(Message::Move(Point { x: 10, y: 15 }));
|
||||||
state.process(Message::Quit);
|
state.process(Message::Quit);
|
||||||
|
|
||||||
assert_eq!(state.color, (255, 0, 255));
|
assert_eq!(state.color, (255, 0, 255));
|
||||||
|
assert_eq!(state.width, 10);
|
||||||
|
assert_eq!(state.height, 30);
|
||||||
assert_eq!(state.position.x, 10);
|
assert_eq!(state.position.x, 10);
|
||||||
assert_eq!(state.position.y, 15);
|
assert_eq!(state.position.y, 15);
|
||||||
assert_eq!(state.quit, true);
|
assert_eq!(state.quit, true);
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn build_scores_table(results: String) -> HashMap<String, Team> {
|
||||||
let team_2_score: u8 = v[3].parse().unwrap();
|
let team_2_score: u8 = v[3].parse().unwrap();
|
||||||
// TODO: Populate the scores table with details extracted from the
|
// TODO: Populate the scores table with details extracted from the
|
||||||
// current line. Keep in mind that goals scored by team_1
|
// current line. Keep in mind that goals scored by team_1
|
||||||
// will be the number of goals conceded from team_2, and similarly
|
// will be the number of goals conceded by team_2, and similarly
|
||||||
// goals scored by team_2 will be the number of goals conceded by
|
// goals scored by team_2 will be the number of goals conceded by
|
||||||
// team_1.
|
// team_1.
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,7 +468,7 @@ path = "exercises/08_enums/enums2.rs"
|
||||||
mode = "compile"
|
mode = "compile"
|
||||||
hint = """
|
hint = """
|
||||||
You can create enumerations that have different variants with different types
|
You can create enumerations that have different variants with different types
|
||||||
such as no data, anonymous structs, a single string, tuples, ...etc"""
|
such as anonymous structs, structs, a single string, tuples, no data, ...etc"""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "enums3"
|
name = "enums3"
|
||||||
|
|
Loading…
Reference in a new issue