pub enum EvolvedEevee {
    Vaporeon(Eevee, u16),
    Flareon(Eevee, u16),
    Leafeon(Eevee, u16),
}
Expand description

This type represent an evolved Eevee in the form of either Vaporeon, Flareon, or Leafeon.

An EvolvedEevee contains an inner Eevee as well as a secondary attribute value. This attribute value changes one of the inner Eevee’s base stats depending on which of the 3 types the EvolvedEevee is.

Variants§

§

Vaporeon(Eevee, u16)

The secondary attribute for Vaporeon is added to the base health.

§

Flareon(Eevee, u16)

The secondary attribute for Flareon is added to the base attack.

§

Leafeon(Eevee, u16)

The secondary attribute for Leafeon is added to the base defense.

Implementations§

source§

impl EvolvedEevee

There’s a lot of boiler plate code here that we’ll implement for you. All you need to do is implement take_damage and devolve.

In all honesty, if you had to actually implement this logic, you would probably have each EvolvedEevee variant be its own standalone type, each implementing something called a trait. However, we haven’t talked about traits yet, so stay tuned till week 5!

source

pub fn get_level(&self) -> u8

source

pub fn get_health(&self) -> u16

source

pub fn get_attack(&self) -> u16

source

pub fn get_defense(&self) -> u16

source

pub fn set_secondary_attribute(&mut self, extra: u16)

source

pub fn take_damage(&mut self, damage: u16)

Deals damage amount of damage to the EvolvedEevee’s health.

This is similar to Eevee::take_damage, but the logic is slightly different for Vaporeon and Flareon, since they have extra health and extra defense, respectively.

For Vaporeon, you will want to apply the damage to the extra health, until the extra health runs out. For Leafeon, you apply the extra defense on every take_damage call.

It’s also fine to just panic with the same message, "Eevee fainted!".

let mut flareon = Eevee::new().evolve(ElementalStone::PyroStone);
flareon.take_damage(40);
assert_eq!(flareon.get_health(), 80);

let mut vaporeon = Eevee::new().evolve(ElementalStone::HydroStone);
vaporeon.set_secondary_attribute(20); // Adds 20 extra health
vaporeon.take_damage(40);
assert_eq!(vaporeon.get_health(), 100);

let mut leafeon = Eevee::new().evolve(ElementalStone::MossyStone);
leafeon.set_secondary_attribute(5); // Adds 5 extra defense
for _ in 0..100 {
    leafeon.take_damage(25);
}
assert_eq!(leafeon.get_health(), 100);
source

pub fn devolve(self) -> Eevee

Devolves an EvolvedEevee into an Eevee.

Note that base stats like health should not change even after devolving.

let leafeon = Eevee::new().evolve(ElementalStone::MossyStone);
assert!(matches!(leafeon, EvolvedEevee::Leafeon(_, _)));

let back_to_eevee: Eevee = leafeon.devolve();

Trait Implementations§

source§

impl Debug for EvolvedEevee

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<EvolvedEevee> for EvolvedEevee

source§

fn eq(&self, other: &EvolvedEevee) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for EvolvedEevee

source§

impl StructuralEq for EvolvedEevee

source§

impl StructuralPartialEq for EvolvedEevee

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.