35 lines
694 B
Rust
35 lines
694 B
Rust
use anyhow::Result;
|
|
use serde::Deserialize;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct Card {
|
|
pub name: String,
|
|
pub types: Vec<String>,
|
|
pub uuid: String,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CardDB {
|
|
data: HashMap<String, Card>,
|
|
}
|
|
|
|
impl CardDB {
|
|
pub fn load(data: Vec<u8>) -> Result<Self> {
|
|
Ok(serde_json::from_slice(&data)?)
|
|
}
|
|
|
|
pub fn get_by_uuid(&self, uuid: &String) -> Option<&Card> {
|
|
self.data.get(uuid)
|
|
}
|
|
}
|
|
|
|
impl Card {
|
|
pub fn is_type(&self, card_type: &str) -> bool {
|
|
// Iter through types
|
|
self.types
|
|
.iter()
|
|
.any(|t| t.to_lowercase() == card_type.to_lowercase())
|
|
}
|
|
}
|