Skip to content

On-demand functions using macros #676

@steveklabnik

Description

@steveklabnik

Issue by s-panferov
Monday Oct 20, 2014 at 18:12 GMT

For earlier discussion, see rust-lang/rust#18191

This issue was labelled with: B-RFC in the Rust repository


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

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions