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)]
pub enum Team {
    #[serde(rename = "Red")]
    RED,
    #[serde(rename = "Blue")]
    BLUE,
    #[serde(rename = "Neutral")]
    NEUTRAL,
}

impl Display for Team {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Team::RED => write!(f, "Red"),
            Team::BLUE => write!(f, "Blue"),
            Team::NEUTRAL => write!(f, "Neutral"),
        }
    }
}

impl FromStr for Team {
    type Err = String;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Red" => Ok(Team::RED),
            "Blue" => Ok(Team::BLUE),
            "Neutral" => Ok(Team::NEUTRAL),
            _ => Err(format!("{s} is not a valid team")),
        }
    }
}