fanduel_data/models/
matchup.rs1use crate::FanduelDataError;
2use nfl_model::TeamAbbr;
3use std::fmt::{Display, Formatter};
4use std::str::FromStr;
5
6#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
11pub struct Matchup {
12 pub away: TeamAbbr,
14 pub home: TeamAbbr,
16}
17
18impl FromStr for Matchup {
19 type Err = FanduelDataError;
20
21 fn from_str(s: &str) -> Result<Self, Self::Err> {
22 let (away, home) = s
23 .split_once('@')
24 .ok_or(FanduelDataError::MatchupParseError(s.to_string()))?;
25 let home = home
26 .parse::<TeamAbbr>()
27 .map_err(|_| FanduelDataError::MatchupParseError(s.to_owned()))?;
28 let away = away
29 .parse::<TeamAbbr>()
30 .map_err(|_| FanduelDataError::MatchupParseError(s.to_owned()))?;
31 Ok(Matchup { away, home })
32 }
33}
34
35impl Display for Matchup {
36 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
37 write!(f, "{}@{}", self.away, self.home)
38 }
39}