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

Create #[derive(Views)] macro for collections #292

Open
ModProg opened this issue Apr 25, 2023 · 0 comments
Open

Create #[derive(Views)] macro for collections #292

ModProg opened this issue Apr 25, 2023 · 0 comments

Comments

@ModProg
Copy link
Collaborator

ModProg commented Apr 25, 2023

My idea would be to allow something like:

#[drive(Collection, Views)]
#[collection(name="timer")]
#[view(TimerIsRunning, name = "timer_by_running", condition = |document| document.contents.running)] // Creates a View that emits all Documents where running = true
pub struct Timer {
    #[view(TimerByRunning. name = "timer_by_running")] // Creates a View, that emits the key `running`
    #[view(TimerIsRunning, name = "timer_by_running", when_eq = true)] // Creates a View that emits all Documents where running = true
    pub running: bool
}

First argument to #[view(...)] would be the struct name of the view, following would be the properties.

Multiple attributes with the same struct name would be the same view.

I think there is more to add here, just some initial ideas. There is also probably a limit till where it makes sense to be able to derive it like so, and after which a custom implementation will be more sensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant