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

On-demand functions using macros #676

Closed
steveklabnik opened this Issue Jan 21, 2015 · 3 comments

Comments

Projects
None yet
5 participants
@steveklabnik
Copy link
Member

steveklabnik commented Jan 21, 2015

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.

@mneumann

This comment has been minimized.

Copy link

mneumann commented Jan 27, 2015

I think this could be implemented right now with a find_by! marco. Usage would look like this (not sure if macros work with dot-notation):

user_model.find_by!( id = 100u );
user_model.find_by!( first_name = "Luke", last_name = "Skywalker" );
@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jul 28, 2016

This is currently a syntax error.

error: expected one of `.`, `::`, `;`, `?`, `}`, or an operator, found `!`
 --> <anon>:3:23
3 |>     user_model.find_by!( id = 100u );
  |>                       ^
@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Oct 7, 2018

Closing in favor of #2442.

@Centril Centril closed this Oct 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.