-
-
Notifications
You must be signed in to change notification settings - Fork 692
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
feat: add a derive macro for create_slice()
#1867
Conversation
Improvement ideasThis could even be more concise, if the trait provides
Which is even nicer. Another idea would be to introduce a A rough concept would look like this:
|
A function-like I'm honestly more fond of the function-like @gbj |
@SadraMoh Thanks for your work on this! I don't understand the name slice!(state.count); just expands to create_slice(
state
|st: &_| st.count.clone(),
|st: &mut _, n| st.count = n
) This makes perfect sense to me and is a nice shorthand. @jquesada2016 Do you have feedback on the derive macro API here, since it was your idea? |
Hey, sorry for the late reply, I've been locked out of my email for a while because my phone broke and had to wait to get it fixed for MFA to work :/ I actually like @gbj's syntax of What I was thinking was something like: #[derive(Slice)[ // or Lens, or Prism, or whatever
struct State {
count: i32,
name: String,
} which expands to something akin to: struct State {
count: i32,
name: String,
}
#[derive(Clone, Copy)]
struct StateSlice { // or StateLens, or StatePrism, or whatever...
count: RwSignal<i32>,
name: name: RwSignal<String>
}
impl StateSlice {
pub fn new(state: State) -> Self { /* ... */ }
pub fn split(self) -> (StateSliceRead, StateSliceWrite) { /* ... */ }
}
#[derive(Clone, Copy)]
struct StateSliceRead {
count: ReadSignal<i32>,
name: ReadSignal<String>,
}
#[derive(Clone, Copy)]
struct WriteSliceRead {
count: WriteSignal<i32>,
name: WriteSignal<String>,
} |
Slice might not be the best name...the idea was to be able to easily bundle up multiple |
I removed the incomplete |
Awesome! Thanks! The CI issues here are unrelated, this all looks good to me. |
Fixes #1635
I still need to work on this (issue with nested structs) but it should illustrate the general idea.
The new
#[derive(Lens)]
macro is appliable to all global state structs (field structs and tuple structs) and generates "Lens constructor functions" for every field of the struct.