use serde_derive::{Serialize, Deserialize}; use thiserror::Error; use std::collections::BTreeMap; use std::str::FromStr; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Poseidoc { pub config: toml::Value, pub entities: BTreeMap, } #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Entity { pub name: String, //location: SourceLocation pub language: Language, pub kind: EntityKind, pub brief_description: String, pub documentation: String, pub children: Children, } pub type Children = BTreeMap>; // TODO: use newtype for entity kind, entity ID #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(try_from = "&str", into = "&'static str")] pub enum Language { Clang, } impl std::fmt::Display for Language { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", <&'static str>::from(*self)) } } impl FromStr for Language { type Err = LanguageParseError; fn from_str(s: &str) -> Result { match s { "clang" => Ok(Language::Clang), _ => Err(LanguageParseError(())), } } } impl std::convert::TryFrom<&str> for Language { type Error = LanguageParseError; fn try_from(s: &str) -> Result { Language::from_str(s) } } impl From for &'static str { fn from(lang: Language) -> &'static str { match lang { Language::Clang => "clang", } } } #[derive(Debug, Clone, PartialEq, Eq, Hash, Error)] #[error("invalid language")] pub struct LanguageParseError(()); #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(transparent)] pub struct EntityKind(pub String); // Plural version of EntityKind #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(transparent)] pub struct ChildrenKind(pub String); #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(transparent)] pub struct EntityId(pub String);