flams_ontology/content/declarations/mod.rs
1pub mod morphisms;
2pub mod structures;
3pub mod symbols;
4
5use super::modules::NestedModule;
6use crate::{ Checked, CheckingState};
7use morphisms::Morphism;
8use structures::{Extension, MathStructure};
9use symbols::Symbol;
10
11pub(super) mod private {
12 pub trait Sealed {}
13}
14pub trait DeclarationTrait: private::Sealed+std::fmt::Debug {
15 fn from_declaration(decl: &Declaration) -> Option<&Self>;
16}
17
18#[derive(Debug)]
19pub enum OpenDeclaration<State:CheckingState> {
20 NestedModule(NestedModule<State>),
21 Import(State::ModuleLike),
22 Symbol(Symbol),
23 MathStructure(MathStructure<State>),
24 Morphism(Morphism<State>),
25 Extension(Extension<State>),
26}
27
28pub type Declaration = OpenDeclaration<Checked>;
29impl private::Sealed for Declaration {}
30impl DeclarationTrait for Declaration {
31 #[inline]
32 fn from_declaration(decl: &Declaration) -> Option<&Self> {
33 Some(decl)
34 }
35}
36
37crate::serde_impl! {
38 enum OpenDeclaration{
39 {0 = NestedModule(nm)}
40 {1 = Import(ml)}
41 {2 = Symbol(s)}
42 {3 = MathStructure(s)}
43 {4 = Morphism(m)}
44 {5 = Extension(e)}
45 }
46}
47
48/*
49crate::serde_impl! {
50 OpenDeclaration : slf
51 ser => {
52 match slf {
53 Self::NestedModule(nm) => {
54 ser.serialize_newtype_variant(
55 "OpenDeclaration",
56 0,
57 "NestedModule", nm
58 )
59 }
60 _ => todo!()
61 }
62 }
63 de => {
64 struct Visitor;
65 impl<'de> serde::de::Visitor<'de> for Visitor {
66 type Value = OpenDeclaration<Unchecked>;
67 fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
68 formatter.write_str(stringify!(OpenDeclaration))
69 }
70 fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
71 where
72 A: EnumAccess<'de>,
73 {
74 let (v,var) = data.variant()?;
75 match v {
76 "NestedModule" => {
77 var.newtype_variant().map(|e| OpenDeclaration::NestedModule(e))
78 }
79 _ => todo!()
80 }
81
82 }
83 }
84 de.deserialize_enum(
85 "OpenDeclaration",
86 &["NestedModule","Import","Symbol","MathStructure","Morphism","Extension"],
87 Visitor
88 )
89 }
90}
91*/