Skip to content

s-panferov/dsl-macros

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

This macro can be used with various builders that use closures for configuration. Macro rewrites only simple method calls without a path and leaves other expressions as-is. It do not touch calls like builder.method(), module::method() or Class::method(). Type parameters work as expected, so you can use method<T>() and the macro converts it to context.method<T>().

Сompatible libraries

  1. Rustless — REST-like API micro-framework for Rust. Works with Iron.
  2. jsonway — JSON building DSL and configurable serializers for Rust.
  3. valico — JSON Schema validator and JSON coercer.
  4. Any other library that uses the same pattern for building blocks.

Usage

Source:

dsl!(|context, other_arg1, other_arg2, /* .. */| {
    method_of_context(other_arg1);
    another_method_of_context(other_arg2);
})

Result:

|context, other_arg1, other_arg2, /* .. */| {
    context.method_of_context(other_arg1);
    context.another_method_of_context(other_arg2);
}

Examples

Without DSL:

rustless::Namespace::build("tweets", |tweets| {
    tweets.get("latest", |endpoint| {
        endpoint.desc("Get latest tweets");
        endpoint.handle(|client, _params| {
            // body omitted
        })
    });

    tweet.post(/* omitted */);
    tweet.delete(/* omitted */);
})

With DSL:

rustless::Namespace::build("tweets", dsl!(|tweets| {
    get("latest", dsl!(|endpoint| {
        desc("Get latest tweets");
        handle(|client, _params| {
            // body omitted
        })
    }));

    post(/* omitted */);
    delete(/* omitted */);
}))

About

Convenience macros for Rust that rewrites method calls inside a builder closure.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages