- 001 - Bulbizarre
- 004 - Salameche
- 025 - Pikachu
- 098 - Krabby
- let
- String
- mut
- Create a Pikachu
- Create a Pokemon struct with id, name
- Println
- Create a Salameche
- Create a Appears method
- Println
- Borrow checker => &
- Create Core folder
- Create a pokemon file
- Change the visibility of Pokemon attributes
- Create a Poketype struct with name
- Create
- Update Pokemon :
- Add a Vec attributes
- Create function add_type
- Create function add_type
- Create a new constructor
- Create a CanBeNammed trait with func:
- get_my_name
- who_am_i
- Impl for Pokemon and Poketype
- Add implicit trait #[derive(Debug)] for Pokemon and Poketype
- Create a show method with sign :
fn show<T: CanBeNammed + std::fmt::Debug>(struct_to_show: &T)
- Create a Pokeball with
#[derive(Debug)]
pub struct Pokeball<'a> {
name: String,
pokemon: &'a Pokemon,
}
impl<'a> Pokeball<'a> {
pub fn new(name: String, pokemon: &'a Pokemon) -> Pokeball {
Pokeball { name, pokemon }
}
}
impl<'a> CanBeNammed for Pokeball<'a> {
fn get_my_name(&self) -> String {
format!("{} et je contiens un {:#?}", &self.name, &self.pokemon.name).to_string()
}
}
- Add an optional Pokemon attributes to Pokeball
- Update get_my_name
- Add get_pokemon() func to Pokeball with Result<>
- Add a masterball
let pokeball = Pokeball::new("pokeball".to_string(), Some(bulbizarre));
show(&pokeball);
pokeball.who_am_i();
match pokeball.get_pokemon() {
Ok(pokemon) => pokemon.who_am_i(),
Err(error_message) => println!("{}", error_message),
}