lunatic-solutions/submillisecond

Named params extractor

tqwewe opened this issue · 0 comments

Add trait for extracting params via their name.

pub trait NamedParam {
    type Rejection: IntoResponse;

    fn name() -> &'static str;
    fn extract(req: &Request) -> Result<Self, Self::Rejection>;
}

And can be implemented manually:

struct AgeParam(i32);

impl NamedParam for AgeParam {
    type Rejection = ...;
    
    fn name() -> &'static str { "age" }
    fn extract() -> ...
}

But more conveniently, can be implemented with a derive macro we provide:

#[derive(NamedParam)]
#[name("age")]
struct AgeParam(i32);

fn foo(AgeParam(age): AgeParam) { ... }