Skip to content

Commit 6bd1e0f

Browse files
committed
chore : separate pokemon struct
J'ai séparé la struct pokemon et rendu public ses champs
1 parent 35a9402 commit 6bd1e0f

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/gen1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::Pokemon;
1+
use crate::pokemon::Pokemon;
22

33
pub fn gen1_pokedex() -> Vec<Pokemon> {
44
vec![

src/main.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use colored::*;
22
use std::collections::{HashMap, HashSet};
33
use std::io::{self, Write};
4-
mod gen1;
4+
5+
pub mod gen1;
6+
pub mod pokemon;
7+
8+
pub use crate::pokemon::Pokemon;
59

610
type Pokedex = HashMap<String, HashSet<String>>;
711

@@ -89,21 +93,6 @@ fn add_pokemon_from_input(dex: &mut Pokedex) {
8993
add_pokemon(dex, &p_type, &nom);
9094
}
9195

92-
#[derive(Debug)]
93-
struct Pokemon {
94-
nom: String,
95-
p_type: String,
96-
}
97-
98-
impl Pokemon {
99-
fn new(nom: &str, p_type: &str) -> Self {
100-
Self {
101-
nom: nom.to_string(),
102-
p_type: p_type.to_string(),
103-
}
104-
}
105-
}
106-
10796
fn main() {
10897
println!("initialisation du pokedex...");
10998
let mut dex = init_pokedex();

src/pokemon.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[derive(Debug)]
2+
pub struct Pokemon {
3+
pub nom: String,
4+
pub p_type: String,
5+
}
6+
7+
impl Pokemon {
8+
pub fn new(nom: &str, p_type: &str) -> Self {
9+
Self {
10+
nom: nom.to_string(),
11+
p_type: p_type.to_string(),
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)