overloadable

Crates.iooverloadable
lib.rsoverloadable
version0.4.1
sourcesrc
created_at2019-07-13 22:59:15.375893
updated_at2019-08-08 21:14:18.25861
descriptionOverloadable functions done easy in rust.
homepage
repositoryhttps://github.com/OptimisticPeach/overloadable.git
max_upload_size
id148856
size19,671
Patrik Buhring (OptimisticPeach)

documentation

README

overloadable

Easy to use overloadable functions in rust using nightly features.

This crate provides you with the capabilities to overload your functions in a similar style to C# or C++, including support for meta attributes, type parameters and constraints, and visibility modifiers. Please visit the documentation for futher information.

Note

This is a nightly crate. You must include the following line in your code for this crate to compile:

#![feature(unboxed_closures, fn_traits)]

Example:

#![feature(unboxed_closures, fn_traits)]
use overloadable::overloadable;

overloadable! {
    pub func as
    #[inline(always)]
    fn(x: usize, y: usize) -> usize {
        x * y
    },
    fn<'a>(x: &'a usize) -> f32 {
        *x as f32
    },
    fn<'a, T>(x: &'a [T]) -> &'a T where T: std::fmt::Debug {
        println!("Found {:?}", &x[0]);
        &x[0]
    }
}

fn foo() {
    assert_eq!(func(2, 3), 6);
    assert_eq!(func(&32), 32.0);
    assert_eq!(func(&[1, 2, 3, 4][..]), &0);
}
Commit count: 19

cargo fmt