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

Declarative API #1

Open
kaleidawave opened this issue Jan 30, 2023 · 0 comments
Open

Declarative API #1

kaleidawave opened this issue Jan 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@kaleidawave
Copy link
Owner

Currently the way to create an implementation is to create a new Trait structure with a vector of TraitItems with their respective handlers. The handlers are call-backs that are fired for every structure.

These handlers are currently imperative in the way the handler evaluates the input and reads the data to generate a token stream. A possible way could be to generate a trait and it's handlers using a declarative form from a TokenStream generated by quote:

let my_trait = Trait::from_tokens(quote! {
    trait ::my_crate::MyTrait {
        fn method_one(&self) {
            #(do_thing(self.*);)*
        }
    }
});

This should be possible by creating a ComputedBody struct which implements for<'a> Fn(Item<'a>) -> HandlerResult and evaluates based on the declaration in the token stream.

Few complications:

  • How to do a basic set of things declarative
  • Where to draw the line as to where an imperiative implementation is required
  • How to parse the token stream especially function bodies
@kaleidawave kaleidawave added the enhancement New feature or request label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant