shio-rs icon indicating copy to clipboard operation
shio-rs copied to clipboard

Procedural macro for routing

Open Meralis40 opened this issue 8 years ago • 8 comments

This is the first part for procedural macro for routing, very basic, only GET and POST. This is currently nightly-only (relies on procedural macro attributes, not stable yet). It's exposed into shio and shio::prelude under the nightly feature.

See the hello_macros examples for how to use it for get request.

Meralis40 avatar Sep 08 '17 07:09 Meralis40

Coverage Status

Coverage remained the same at 79.762% when pulling 9119358b0b5743c68a13f1262a3c72a343c0996a on Meralis40:shio-macro into 033a0b599af8f1564b097e4019883c2aab59c4be on mehcode:master.

coveralls avatar Sep 08 '17 07:09 coveralls

Coverage Status

Coverage remained the same at 79.762% when pulling 4d433c11a644da53ba62edec2e5ab5457bf9de4d on Meralis40:shio-macro into 033a0b599af8f1564b097e4019883c2aab59c4be on mehcode:master.

coveralls avatar Sep 08 '17 08:09 coveralls

#[allow(non_camel_case_types)]
struct __shio_route_hello {
}
impl Clone for __shio_route_hello {
    fn clone(&self) -> Self { *self }
}
impl Copy for __shio_route_hello { }
#[allow(non_upper_case_globals)]
static hello: __shio_route_hello = __shio_route_hello{};
impl Into<::shio::router::Route> for __shio_route_hello {
    fn into(self) -> ::shio::router::Route {
        (::shio::Method::Get, "/{name}", __shio_handler_hello).into()
    }
}

Neat solution to non-moveable statics with the newtype plus impl. I'd suggest shortening it up a bit with a ZST:

#[allow(non_camel_case_types)]
struct hello;
impl Into<::shio::router::Route> for hello {
    fn into(self) -> ::shio::router::Route {
        (::shio::Method::Get, "/{name}", __shio_handler_hello).into()
    }
}

mehcode avatar Sep 12 '17 05:09 mehcode

@Meralis40 Over all, nice work! Let's get this cleaned up a bit and we can merge it in.

I'd love to see the "standard" methods before this is released though:

  • get
  • post
  • patch
  • put
  • delete
  • options
  • head

mehcode avatar Sep 12 '17 05:09 mehcode

@mehcode All changes have been done, except complete clippy, because of "needless_pass_by_value" warning. Also, I've change the generated code as suggested & added the "standard" methods

Meralis40 avatar Sep 12 '17 06:09 Meralis40

Coverage Status

Coverage remained the same at 79.762% when pulling cfd41a2a56f0d3eb877421ce76e1b143276326d6 on Meralis40:shio-macro into 033a0b599af8f1564b097e4019883c2aab59c4be on mehcode:master.

coveralls avatar Sep 12 '17 06:09 coveralls

Rebased

Meralis40 avatar Sep 15 '17 06:09 Meralis40

Coverage Status

Coverage remained the same at 80.699% when pulling 81786a575b93a793019ba7079144337a3084bf71 on Meralis40:shio-macro into 724880d5e5e644d63df096445b912a2fa36bcaf1 on mehcode:master.

coveralls avatar Sep 15 '17 06:09 coveralls