From 70584a4d01cca3cadee4b1232385a7fd15d154ca Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 25 Dec 2019 00:14:43 -0800 Subject: [PATCH] base impls for what weapontype needs --- src/item/weapon.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/item/weapon.rs b/src/item/weapon.rs index 127ef6a..a69c1ce 100644 --- a/src/item/weapon.rs +++ b/src/item/weapon.rs @@ -1,3 +1,4 @@ +use std::convert::{TryFrom, Into}; use std::io::{Read, Seek}; use crate::{PSOPacketData, PacketParseError}; @@ -63,6 +64,9 @@ pub enum WeaponSpecial { Demons, } +pub enum WeaponTypeError { + UnknownWeapon(String) +} #[derive(Debug, Copy, Clone)] pub enum WeaponType { @@ -81,6 +85,27 @@ impl WeaponType { } } +impl TryFrom<&str> for WeaponType { + type Error = WeaponTypeError; + fn try_from(value: &str) -> Result { + match value { + "Saber" => Ok(WeaponType::Saber), + "Handgun" => Ok(WeaponType::Handgun), + "Cane" => Ok(WeaponType::Cane), + _ => Err(WeaponTypeError::UnknownWeapon(value.to_string())) + } + } +} + +impl Into for WeaponType { + fn into(self) -> String { + match self { + WeaponType::Saber => "Saber", + WeaponType::Handgun => "Handgun", + WeaponType::Cane => "Cane", + }.to_string() + } +} #[derive(Debug, Copy, Clone)]