tk3369 / BinaryTraits.jl

Can do or not? It's easy. See https://tk3369.github.io/BinaryTraits.jl/dev/
MIT License
51 stars 3 forks source link

Feature Request: Allow Traits to Subtype Arbitrary Type #59

Closed SBuercklin closed 1 year ago

SBuercklin commented 1 year ago

It would be helpful if we could have traits subtype some type we define, rather than Any. This allows us to filter traits by supertype when generating documentation.

For example, say I want to make an Animal interface, and then I have Fish and Bird traits as well each with their own interface that is independent of Animal. I add a docstring to each of these Animal, Fish, Bird traits to document the interface they must satisfy.

Now I want to make a Habitat interface, and within that I have Water and Tree traits which each include their own interfaces. Again, I document the interface in the trait itself.

I would like to generate a Documenter.jl page which includes all of the Animal interfaces, and another page which includes all of the Habitat interfaces with @autodocs. Currently, we can do this by manually including the docstrings for each trait or restricting trait implementations to particular files, but it would be helpful if I could filter the trait types according to the Julia type hierarchy to generate my interface documentation.

In the end, I'd like to generate an Animals interface page via

@autodocs
Module = [Foo]
Filter = t -> typeof(t) === DataType && t <: Foo.AbstractAnimal

where AbstractAnimal <: Any is an abstract type I create to make sure that {Animal, Fish, Bird} <: Abstract Animal are all independent types in the type tree

Relevant link to the Documenter.jl docs

SBuercklin commented 1 year ago

Closing as this is already implemented with

@trait Animal as AbstractAnimal

Docs cover it here