use std::convert::Infallible; use std::path::Path; use std::str::FromStr; use serde::{Deserialize, Serialize}; use ts_rs::TS; use yasi::InternedString; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, TS)] #[ts(type = "string")] pub struct ReplayId(InternedString); impl From for ReplayId where T: Into, { fn from(value: T) -> Self { Self(value.into()) } } impl FromStr for ReplayId { type Err = Infallible; fn from_str(s: &str) -> Result { Ok(ReplayId(InternedString::intern(s))) } } impl AsRef for ReplayId { fn as_ref(&self) -> &ReplayId { self } } impl std::fmt::Display for ReplayId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.0) } } impl AsRef for ReplayId { fn as_ref(&self) -> &str { self.0.as_ref() } } impl AsRef for ReplayId { fn as_ref(&self) -> &Path { self.0.as_ref() } } impl<'de> Deserialize<'de> for ReplayId { fn deserialize(deserializer: D) -> Result where D: serde::de::Deserializer<'de>, { Ok(ReplayId(serde::Deserialize::deserialize(deserializer)?)) } }