| Crates.io | compose-macro |
| lib.rs | compose-macro |
| version | 0.1.0 |
| created_at | 2025-01-17 02:04:54.608499+00 |
| updated_at | 2025-01-17 02:04:54.608499+00 |
| description | A macro for composing functions |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1520195 |
| size | 7,936 |
A Rust macro for function composition, enabling you to combine multiple functions into a single function effortlessly. This crate also serves as an educational resource for understanding Rust's procedural macros.
To use the compose macro in your Rust project, add the following to your Cargo.toml:
[dependencies]
compose-macro = "0.1.0"
Ensure you have Rust installed. If not, you can install it from rustup.rs.
The compose! macro allows you to chain functions together. Here's a basic example:
use compose_macro::compose;
fn h(x: i32) -> i32 {
x * 2
}
fn g(x: i32) -> i32 {
x * 3
}
fn k(x: i32) -> i32 {
x * 4
}
fn main() {
let composed_function = compose!(h -> g -> k);
let result = composed_function(2);
println!("Result: {}", result); // Output: Result: 48
}
This crate is not only a tool for function composition but also a practical example of how to create and use procedural macros in Rust. Procedural macros allow you to operate on Rust code at compile time, enabling powerful code generation and transformation capabilities.
The compose! macro is implemented as a procedural macro, which parses the input tokens, constructs a new function composition, and generates the corresponding Rust code. This makes it an excellent resource for developers looking to understand and experiment with Rust's macro system.
Here's a brief overview of how the procedural macro works:
For more details, you can explore the source code in the compose-macro directory.
The compose! macro does not require any configuration. It works out of the box with any functions that match the expected input and output types.
We welcome contributions! Please follow these steps to contribute:
For coding standards, please refer to the Rust API Guidelines.
This project is licensed under the MIT License. See the LICENSE file for details.
For support, please open an issue on the GitHub repository.