valorant_api 0.3.14

A library for interacting with the ingame Valorant-API.
Documentation
use std::fmt::Display;
use std::str::FromStr;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Copy)]
#[serde(rename_all = "camelCase")]
pub enum EsportsState {
    Completed,
    Unstarted,
    InProgress,
}

impl Display for EsportsState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            EsportsState::Completed => write!(f, "completed"),
            EsportsState::InProgress => write!(f, "in_progress"),
            EsportsState::Unstarted => write!(f, "unstarted"),
        }
    }
}

impl FromStr for EsportsState {
    type Err = String;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "completed" => Ok(EsportsState::Completed),
            "in_progress" => Ok(EsportsState::InProgress),
            "unstarted" => Ok(EsportsState::Unstarted),
            _ => Err(format!("{s} is not a valid state")),
        }
    }
}