use crate::props::parse::FromCompressedList;
use crate::props::{PropertyType, SgfPropError, ToSgf};
use crate::{InvalidNodeError, SgfProp};
use std::collections::HashSet;
sgf_prop! {
Prop, String, String, String,
{ }
}
pub type Point = String;
pub type Stone = String;
pub type Move = String;
impl SgfProp for Prop {
type Point = Point;
type Stone = Stone;
type Move = Move;
fn new(identifier: String, values: Vec<String>) -> Self {
Self::parse_general_prop(identifier, values)
}
fn identifier(&self) -> String {
match self.general_identifier() {
Some(identifier) => identifier,
None => panic!("Unimplemented identifier for {:?}", self),
}
}
fn property_type(&self) -> Option<PropertyType> {
self.general_property_type()
}
fn validate_properties(properties: &[Self], is_root: bool) -> Result<(), InvalidNodeError> {
Self::general_validate_properties(properties, is_root)
}
}
impl std::fmt::Display for Prop {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let prop_string = match self.serialize_prop_value() {
Some(s) => s,
None => panic!("Unimplemented identifier for {:?}", self),
};
write!(f, "{}[{}]", self.identifier(), prop_string)
}
}
impl FromCompressedList for String {
fn from_compressed_list(ul: &Self, lr: &Self) -> Result<HashSet<Self>, SgfPropError> {
let mut points = HashSet::new();
points.insert(format!("{ul}:{lr}"));
Ok(points)
}
}
impl ToSgf for String {
fn to_sgf(&self) -> String {
self.to_owned()
}
}