microversus_codex 0.1.8

Types and definitions for interfacing with the microversus system
Documentation
use crate::{EncounterResult, InventoryLine, Tribe};
use serde::{Deserialize, Serialize};
use std::{error::Error, fmt};

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum LootServiceResponse {
    Encounter {
        event_id: Option<String>,
        result: EncounterResult,
    },
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum InventoryServiceResponse {
    Contents { items: Vec<InventoryLine> },
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum TribeServiceReponse {
    Tribes(Vec<Tribe>),
    TribeIds(Vec<String>),
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum LoreServiceResponse {
    Success { message: String },
}

#[derive(Debug, Default)]
pub enum ServiceError {
    #[default]
    Unknown,
    RustError(String),
}

impl Error for ServiceError {}

impl fmt::Display for ServiceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::Unknown => write!(f, "Unknown error"),
            Self::RustError(text) => write!(f, "{}", text),
        }
    }
}