use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SiteEntity {
Person(String),
Organization(String),
}
impl SiteEntity {
#[must_use]
pub fn person(name: impl Into<String>) -> Self {
Self::Person(name.into())
}
#[must_use]
pub fn organization(name: impl Into<String>) -> Self {
Self::Organization(name.into())
}
#[must_use]
pub const fn schema_type(&self) -> &'static str {
match self {
Self::Person(_) => "Person",
Self::Organization(_) => "Organization",
}
}
#[must_use]
pub fn name(&self) -> &str {
match self {
Self::Person(name) | Self::Organization(name) => name,
}
}
}
#[cfg(test)]
mod tests {
use super::SiteEntity;
#[test]
fn the_schema_type_follows_the_constructor_that_was_used() {
let expected: &str = "Person";
let actual: &str = SiteEntity::person("Todd Everett Griffin").schema_type();
assert_eq!(expected, actual);
let expected: &str = "Organization";
let actual: &str = SiteEntity::organization("Palms Small Engine").schema_type();
assert_eq!(expected, actual);
}
#[test]
fn the_name_survives_either_constructor() {
let expected: &str = "Triple Entendre";
let actual: SiteEntity = SiteEntity::organization("Triple Entendre");
assert_eq!(expected, actual.name());
}
}