add as_str to Weapon

This commit is contained in:
Robin Appelman 2026-11-13 14:50:49 +01:00
commit 74540420f4
Signed by: robin
SSH key fingerprint: SHA256:kifqgrqnut7q1YUIrI0AdMNC23qiKAS/T9uGFmIYvbE

View file

@ -186,14 +186,20 @@ pub enum Weapon {
Other(String), Other(String),
} }
impl Weapon {
pub fn as_str(&self) -> &str {
match self {
Weapon::Other(other) => other.as_str(),
_ => self.as_ref(),
}
}
}
impl Serialize for Weapon { impl Serialize for Weapon {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: serde::Serializer, S: serde::Serializer,
{ {
match self { self.as_str().serialize(serializer)
Weapon::Other(other) => other.serialize(serializer),
_ => self.as_ref().serialize(serializer),
}
} }
} }