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),
}
impl Weapon {
pub fn as_str(&self) -> &str {
match self {
Weapon::Other(other) => other.as_str(),
_ => self.as_ref(),
}
}
}
impl Serialize for Weapon {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
Weapon::Other(other) => other.serialize(serializer),
_ => self.as_ref().serialize(serializer),
}
self.as_str().serialize(serializer)
}
}