Skip to content

Idea: helper macros #26

Open
Open
@richardanaya

Description

@richardanaya

I was looking over the routing example, and a part of me was wondering if there might be some standardized macros that could help with very common filter patterns. An example:

fn main() {
    let routes = routes!{
        route!{
            warp::index(),
            ||{
                "Welcome!"
            }
        },
        route!{
            path!("hello"/String),
            |name|{
                format!("Hello {}",name)
            }
        }
        route!{
            warp::any(),
            ||{
                "How'd you get here?"
            }
        }
    };

    warp::serve(routes)
        .run(([0, 0, 0, 0], 3030));
}

routes! would .or(...) a chain of filters

route! would .and(...) a chain of filters and .map(...) to the last param function

Please keep in mind i'm a Rust noob so I might be missing some capabilities of macros right now :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    rfcExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions