Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using a trait based API instead of macros #153

Open
kskyten opened this issue Nov 21, 2020 · 3 comments
Open

Consider using a trait based API instead of macros #153

kskyten opened this issue Nov 21, 2020 · 3 comments
Labels
enhancement New feature or request feature_request

Comments

@kskyten
Copy link

kskyten commented Nov 21, 2020

Nice package! I really like the way JSON3.jl handles mapping structs to JSON and back. It does this by annotating structs with traits from StructTypes.jl. I wonder if a similar approach could be used with AcuteML. This way you could easily serialize your struct in either JSON or XML. I'm not sure how well XML maps to the existing StructTypes traits, but there is probably some overlap.

@kskyten
Copy link
Author

kskyten commented Nov 21, 2020

Related to JuliaData/StructTypes.jl#7

Repository owner deleted a comment from issue-label-bot bot Nov 23, 2020
@aminya
Copy link
Owner

aminya commented Nov 23, 2020

AcuteML is like the JSX of Julia. This library aims to make it easy for developers to build their HTML or XML applications with the least amount of boilerplate code. This has several benefits:

  • You can define your components with minimal effort, and everything is handled by AcuteML underneath.
  • The @aml defined types work just like normal Julia types. (e.g. they can be used for dispatching, they can have custom constructors, etc).
  • You can parse or create data with the exact same type. There is no need to manually write methods.
# Here you can serialize any HTML that follows this structure. Serialization here means both parsing and creating.

@aml mutable struct Body "~"
    h1, "~"
    p::Vector{String}, "~"
end

@aml mutable struct Page doc"html"
    body::Body, "~"
end

See MusicXML.jl for an example of a library that uses AcuteML:
https://github.com/JuliaMusic/MusicXML.jl

If you plan to inject custom code to your AcuteML components there are multiple ways you can do this:
https://aminya.github.io/AcuteML.jl/dev/extraConstructors/
https://aminya.github.io/AcuteML.jl/dev/customValueTypes/
https://aminya.github.io/AcuteML.jl/dev/customConstructors/

You can also directly use the AcuteML's backend if you wish (although not necessary at all).

I wrote VarStructs which is similar to AcuteML, but is for any type of data. You can easily define your requirements for data using VarStructs, and everything will be handled for you.

GitHub
Variable Julia Structs with dispatching. Contribute to aminya/VarStructs.jl development by creating an account on GitHub.

@aminya aminya added the wontfix This will not be worked on label Nov 23, 2020
@kskyten
Copy link
Author

kskyten commented Nov 25, 2020

I don't necessarily see how what I'm thinking of is mutually exclusive. Here is an example to clarify this. Say I have a struct

struct Foo
  x::String
  y::Int

and I want to serialize it in XML, JSON and possible some other serialization format. If each of the serialization libraries defines their custom APIs with macros, it is difficult to combine them and they have to be added as dependencies.

I'm asking whether it is possible to use a common API for defining the mapping to various serialization formats like Rust's Serde does. As far as I know, StructTypes.jl comes the closest to this kind of API. If it doesn't suit AcuteML, it would be useful to know what is missing so a better API can be built.

@aminya aminya added enhancement New feature or request and removed wontfix This will not be worked on labels Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature_request
Projects
None yet
Development

No branches or pull requests

2 participants