Crates.io | function_overloading |
lib.rs | function_overloading |
version | 0.1.1 |
source | src |
created_at | 2024-08-08 01:38:43.627001 |
updated_at | 2024-10-23 01:12:18.124513 |
description | a crate that adds function overloading |
homepage | |
repository | https://github.com/chickencuber/function_overloading |
max_upload_size | |
id | 1328949 |
size | 5,864 |
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.
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 macro:
fn main() {
foo!(1, 2); // Outputs: 3
foo!("bar"); // Outputs: bar
let bar: String = foo!('a');
}
-> ()
implicit.