From d3483cc3736e54571d20a1840de67bbb6f166885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 30 Jun 2020 17:18:56 +0200 Subject: [PATCH] pkstrings: Implement Clone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- pkstrings/src/lib.rs | 6 ++++++ savestate/src/party.rs | 5 ++--- savestate/src/species.rs | 8 +++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkstrings/src/lib.rs b/pkstrings/src/lib.rs index 52754e8..6465a1f 100644 --- a/pkstrings/src/lib.rs +++ b/pkstrings/src/lib.rs @@ -101,6 +101,12 @@ impl Deref for PKString { } } +impl Clone for PKString { + fn clone(&self) -> PKString { + PKString(self.0.clone()) + } +} + impl fmt::Display for PKString { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_fmt(format_args!("{}", &self.0)) diff --git a/savestate/src/party.rs b/savestate/src/party.rs index 43f4a33..7fd36f2 100644 --- a/savestate/src/party.rs +++ b/savestate/src/party.rs @@ -86,9 +86,8 @@ impl TryFrom<&[u8]> for PokemonList { for i in 1..=count { let start = PARTY_FIRST_ENTRY_OFFSET + ((i - 1) * PK_FULL_ENTRY_SIZE) - 1; let end = PARTY_FIRST_ENTRY_OFFSET - 1 + (i * PK_FULL_ENTRY_SIZE) - 1; - // TODO: Reimplement Clone on PKString? - let ot_name: PKString = PKString::try_from(ot_names[i - 1].clone())?; - let pk_nick: PKString = PKString::try_from(pk_nicks[i - 1].clone())?; + let ot_name = ot_names[i - 1].clone(); + let pk_nick = pk_nicks[i - 1].clone(); entries.push(IndividualPk::try_from((&data[start..=end], ot_name, pk_nick))?); } diff --git a/savestate/src/species.rs b/savestate/src/species.rs index 80ecc9b..d5cacad 100644 --- a/savestate/src/species.rs +++ b/savestate/src/species.rs @@ -654,13 +654,11 @@ mod tests { #[test] fn test_individual_simple() { - // TODO: Reimplement Clone on PKString? - let ot_name1: PKString = PKString::try_from("FOOBAR").unwrap(); - let ot_name2: PKString = PKString::try_from("FOOBAR").unwrap(); + let ot_name: PKString = PKString::try_from("FOOBAR").unwrap(); let kadabra_nick: PKString = PKString::try_from("KADABRA").unwrap(); let charizard_nick: PKString = PKString::try_from("CHARIZARD").unwrap(); - let pk = IndividualPk::try_from((&KADABRA, ot_name1, kadabra_nick)).unwrap(); + let pk = IndividualPk::try_from((&KADABRA, ot_name.clone(), kadabra_nick)).unwrap(); assert_eq!(pk.species, Species::Kadabra); assert_eq!(pk.current_hp, 44); assert_eq!(pk.level, 16); @@ -677,7 +675,7 @@ mod tests { None, None, ].into()); - let pk = IndividualPk::try_from((&CHARIZARD, ot_name2, charizard_nick)).unwrap(); + let pk = IndividualPk::try_from((&CHARIZARD, ot_name, charizard_nick)).unwrap(); assert_eq!(pk.species, Species::Charizard); assert_eq!(pk.current_hp, 139); assert_eq!(pk.level, 42);