This commit is contained in:
Robin Appelman 2021-08-07 19:03:58 +02:00
commit ca61f4ea6a
8 changed files with 531 additions and 11 deletions

42
src/common.rs Normal file
View file

@ -0,0 +1,42 @@
use crate::raw_event::RawSubject;
use std::str::FromStr;
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Team {
Red,
Blue,
}
impl FromStr for Team {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Blue" => Ok(Team::Blue),
"Red" => Ok(Team::Red),
_ => Err(()),
}
}
}
/// Optimized subject id
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum SubjectId {
Player(u8),
Team(Team),
System,
World,
Console,
}
impl From<&RawSubject<'_>> for SubjectId {
fn from(raw: &RawSubject) -> Self {
match raw {
RawSubject::Player { user_id, .. } => SubjectId::Player(user_id.parse().unwrap()),
RawSubject::Team(team) => SubjectId::Team(team.parse().unwrap()),
RawSubject::System(_) => SubjectId::System,
RawSubject::Console => SubjectId::Console,
RawSubject::World => SubjectId::World,
}
}
}