3 releases (1 stable)
new 1.0.0 | Apr 19, 2025 |
---|---|
0.1.1 | Oct 23, 2024 |
0.1.0 | Aug 8, 2024 |
#461 in Programming languages
137 downloads per month
6KB
79 lines
Function Overloading
This is a Rust library that adds function overloading through Rust macros. It supports normal function syntax but does not currently support advanced features like async, generics, or lifetimes.
Usage
Define overloaded functions using the def!
macro:
def! {
foo; // The name of the function
fn (a: u32, b: u32) {
println!("{}", a + b);
}; // The comma is not optional
fn (s: &str) -> () { // you dont need the return type explicitly
println!("{}", s);
};
fn (s: char) -> String { // You can also have different return types
return s.to_string();
} // You can add a comma at the end, but it's not required
}
You can use the overloaded function by calling it as a function with the args wrapped in a tuple:
fn main() {
foo((1, 2)); // Outputs: 3
foo(("bar")); // Outputs: bar
let bar: String = foo(('a'));
}
Future Plans
- Additional Features: Adding support for generics, lifetimes, async functions, etc.
- Proc Macros: Using proc macros to make
-> ()
implicit.- turns out I didn't need a proc macro for this
- Add to crates.io
Dependencies
~4KB