diff options
| author | troido <troido@protonmail.com> | 2020-05-19 15:06:45 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-05-19 15:06:45 +0200 |
| commit | dac89209fdde17e2e4fdf89768e814945a8cea62 (patch) | |
| tree | 8713ca53fd85b1c88a9263197fa7306766747e19 /src/item.rs | |
| parent | 0d382ea19f8f964c35761f6a3ff80bc9bfc25375 (diff) | |
better json parsing using serde_json::value::from_value
Diffstat (limited to 'src/item.rs')
| -rw-r--r-- | src/item.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/item.rs b/src/item.rs index e4dbb34..0e8661a 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,20 +1,31 @@ use std::collections::HashSet; +use std::str::FromStr; +use serde; +use serde::Deserialize; use serde_json::{Value}; use crate::{ Template, components::{ Flag, equipment::Equippable - } + }, + errors::{ParseError} }; -#[derive(Debug, Default, PartialEq, Eq, Clone, Hash)] +#[derive(Debug, Default, PartialEq, Eq, Clone, Hash, Deserialize)] pub struct ItemId(pub String); +impl FromStr for ItemId { + type Err = ParseError; + fn from_str(s: &str) -> Result<Self, Self::Err> { + Ok(Self(s.to_string())) + } +} + #[derive(Debug, Clone)] pub struct Item { pub ent: Template, |
