aeon/
lib.rs

1use crate::document::AeonDocument;
2use crate::error::{AeonDeserializeError, AeonSerializeError};
3use crate::serializer::AeonFormatter;
4pub mod convert;
5mod deserializer;
6pub mod document;
7pub mod error;
8mod flags;
9mod lexer;
10mod macros;
11mod serializer;
12mod token;
13pub mod value;
14
15pub type DeserializeResult<T> = Result<T, AeonDeserializeError>;
16pub type SerializeResult<T> = Result<T, AeonSerializeError>;
17
18pub fn serialize(aeon: &AeonDocument) -> SerializeResult<String> {
19    if aeon.is_empty {
20        return Ok(String::new());
21    }
22    // TODO: write errors
23    Ok(serializer::PrettySerializer::serialize_aeon(aeon))
24}
25
26pub fn deserialize(s: String) -> DeserializeResult<AeonDocument> {
27    let mut deserializer = deserializer::Deserializer::new(&s);
28    deserializer.deserialize()
29}
30
31pub trait AeonDeserialize
32where
33    Self: Sized,
34{
35    fn from_aeon(s: String) -> DeserializeResult<Self>;
36}
37
38pub trait AeonSerialize {
39    fn to_aeon(&self) -> SerializeResult<String>;
40    // TODO: rebuild this to not perform a bunch of unnecessary steps
41    fn to_aeon_value(&self) -> SerializeResult<value::AeonValue>;
42    fn create_macros(insert_self: bool) -> std::collections::HashMap<String, document::AeonMacro>;
43}
44
45pub trait AeonDeserializeProperty
46where
47    Self: Sized,
48{
49    fn from_property(field: value::AeonValue) -> DeserializeResult<Self>;
50}
51
52pub trait AeonSerializeProperty {
53    // TODO: rebuild this to not perform a bunch of unnecessary steps
54    fn serialize_property(&self) -> SerializeResult<value::AeonValue>;
55    //fn serialize_property_or_nil(&self) -> value::AeonValue;
56    fn create_property_macros(
57        insert_self: bool,
58    ) -> std::collections::HashMap<String, document::AeonMacro>;
59}