Skip to content

On-demand functions using macros #18191

@s-panferov

Description

@s-panferov

I started to write some simple ORM for test purposes and i'm very interested in ability to make some dynamic code generation that could replace Ruby's method_missing.

Pseudo-code to illustrate the idea:

impl UserModel {
    pub fn macro_method (find_by, $($field_name:ident)_and_+) (&self, $($field_value:expr),+) -> SelectQuery {
        self.select_all().where_(
            $(
                self.$field_name().is($field_value),
            )   
        )
    }
}

let query = user_model.find_by_id!(100u);
let query = user_model.find_by_first_name_and_last_name!("Luke", "Skywalker");

What do you think about that? I you not interested please close this issue and never mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions