handler macro

This commit is contained in:
Robin Appelman 2021-08-08 01:06:19 +02:00
commit e846fcceae
5 changed files with 91 additions and 56 deletions

View file

@ -4,12 +4,13 @@ use crate::module::EventHandler;
use crate::raw_event::RawEventType;
use crate::SubjectMap;
use chrono::{DateTime, FixedOffset, NaiveDateTime, TimeZone, Utc};
use serde::{Serialize, Serializer};
use std::num::ParseIntError;
use std::str::{FromStr, ParseBoolError};
use steamid_ng::SteamID;
use thiserror::Error;
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub enum GameType {
Sixes,
Highlander,
@ -27,7 +28,7 @@ impl FromStr for GameType {
}
}
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub enum Location {
Europe,
NorthAmerica,
@ -45,7 +46,7 @@ impl FromStr for Location {
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Serialize)]
pub struct LobbyLeader {
name: String,
steam_id: SteamID,
@ -70,7 +71,7 @@ impl FromStr for LobbyLeader {
}
}
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct Settings {
id: u32,
leader: LobbyLeader,
@ -127,6 +128,15 @@ pub enum LobbySettingsError {
InvalidDate(#[from] chrono::ParseError),
}
impl Serialize for LobbySettingsError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
format!("{}", self).serialize(serializer)
}
}
pub enum LobbySettingsHandler {
NotAvailable,
Active(Settings),