function_overloading

Crates.iofunction_overloading
lib.rsfunction_overloading
version0.1.1
sourcesrc
created_at2024-08-08 01:38:43.627001
updated_at2024-10-23 01:12:18.124513
descriptiona crate that adds function overloading
homepage
repositoryhttps://github.com/chickencuber/function_overloading
max_upload_size
id1328949
size5,864
(chickencuber)

documentation

README

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 macro:

fn main() {
    foo!(1, 2); // Outputs: 3
    foo!("bar"); // Outputs: bar
    let bar: String = foo!('a');
}

Future Plans

  • Improved Syntax: Making the syntax more like defining functions.
  • 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
Commit count: 13

cargo fmt