use alloc::string::String;
use musicxml_internal::{DatatypeDeserializer, DatatypeSerializer};
#[derive(Debug, PartialEq, Eq)]
pub enum DistanceType {
Beam,
Hyphen,
Other(String),
}
impl DatatypeSerializer for DistanceType {
fn serialize(element: &Self) -> String {
match element {
Self::Beam => String::from("beam"),
Self::Hyphen => String::from("hyphen"),
Self::Other(text) => text.clone(),
}
}
}
impl DatatypeDeserializer for DistanceType {
fn deserialize(value: &str) -> Result<Self, String> {
Ok(match value {
"beam" => Self::Beam,
"hyphen" => Self::Hyphen,
_ => Self::Other(String::from(value)),
})
}
}
#[cfg(test)]
mod distance_type_tests {
use super::*;
#[test]
fn deserialize_valid() {
let result = DistanceType::deserialize("beam");
assert!(result.is_ok());
assert_eq!(result.unwrap(), DistanceType::Beam);
}
}