olivedae / harald

Rust API for Bluetooth Low Energy
MIT License
29 stars 2 forks source link

[kawaii] nested namespaces #16

Open olivedae opened 8 years ago

olivedae commented 8 years ago

Allow namespaces (and it's accompanying path) to be defined along with related details (e.g. routes and/or nested namespaces).

The 可愛い!(scaffold <etc>) was meant to support nesting due to rustless implementing Nesting and ApiHandler for both Api and Namespace.

A rough example is given below (does include dependency injection).

fn test<'a>(client: Client<'a>, example: String) -> Response<'a> {
    // ...
}

fn other_test<'a>(client: Client<'a>) -> Response<'a> {
    // ...
}

fn main() {
    let application = 
         可愛い!(
             namespace (first/example:string) [
                 get (one) -> test;
                 get (two) -> test;
             ]
             namespace (second/example) [
                 get (one) -> other_test;   
             ]
             get (last/example:string) -> test;
         );

    // ...
}

To be honest, I'm not a huge fan of the brackets but there needs to be some way to tell when the current namespace ends.