Skip to content

A simple proc-macro library that provides a macro to partial bind function arguments using closures.

License

Notifications You must be signed in to change notification settings

ZXY595/partial-bind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Partial Bind

A simple proc-macro library that provides a macro to partial bind function arguments using closures. Which is known as partial function application.

Syntax:

bind!(foo(1, 2, _, _, 3)); // which generates: |__1, __2| foo(1, 2, __1, __2, 3)

Usage:

Case: Add context for api handler in web backend:

let (tx, rx) = async_channel::unbounded();

tokio::spawn(async move {tx.send(1).await.unwrap()});

router.route("/api/1", get(bind!(handler(rx))))

async fn handler(rx: async_channel::Receiver<i32>) -> i32 {
    rx.recv().await.unwrap()
}

About

A simple proc-macro library that provides a macro to partial bind function arguments using closures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages