polimorphism 0.7.3

Function overloading via a procedural macro
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented1 out of 2 items with examples
  • Size
  • Source code size: 16.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 303.56 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Nyx-art/polimorphism
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Nyx-art

polymorphism

A procedural macro to imitate ad hoc polymorphism (function overloading) which can be seen and found in many modern programming languages. Can be used similarly to an fn or impl declaration, but polymorphism allows for duplicate fn names with different signitures (types as parameters). This implementation of polymorphism bypasses the orphan rule with a Local type.


Example

polymorphism!(
    pub fn func(n: i32, m: i32) -> i32 {
        n+m
    }
    pub fn func(n: f64, m: f64) -> f64 {
        n-m
    }
);

assert_eq!(polymorphism!(func(1,2)), 3);
assert_eq!(polymorphism!(func(1.0,2.0)), -1.0);

Notes:

  • This is a proof of concept, therefore it is REALLY unstable
  • It is nearly untested and may break on edge cases
  • Do NOT use it in production codebases at this time
  • Feedback is appreciated :)