Aardwolf-Social / aardwolf

Powering connected social communities with open software.
GNU Affero General Public License v3.0
480 stars 40 forks source link

TODO: Refactor form state into trait #184

Open asonix opened 5 years ago

asonix commented 5 years ago

Something like

pub trait FormWithState {
    type State;

    fn as_state(&self) -> Self::State;
}

impl FormWithState for CreatePostForm {
    type State = CreatePostFormState;

    fn as_state(&self) -> Self::State {
        CreatePostFormState {
            ...
        }
    }
}

And this could even be automated with proc_macros like this

#[derive(FormWithState)]
pub struct CreatePostForm {
    name: Option<String>,
    #[form_with_state(ignore)]
    csrf_token: String,
    ...
}