[−][src]Crate overloadable
This crate provides the ability to create overloadable functions in rust through the use of a macro.
Syntax:
ⓘThis example is not tested
use overloadable::overloadable; overloadable!{ pub function_name as #[doc = "Some meta attributes."] fn<OptionalTypeArgs>(function_params: function_types) -> optional_return_type where OptionalTypeArgs: constraints { code_body } }
What is produced
Here is an example of the output produced by overloadable
:
ⓘThis example is not tested
use overloadable::overloadable; use std::fmt::Debug; overloadable!{ pub my_func as fn(x: usize, y: &str) -> f32 { (x * y.len()) as f32 }, fn<T>() where T: Debug {} } //Gives #[allow(non_camel_case_types)] pub struct my_func_; impl Fn<(usize, &str,)> for my_func { extern "rust-call" fn call(&self, (x, y,): (usize, &str,)) -> f32 { { (x * y.len()) as f32 } } } //The rest of the `Fn*` family impl<T> Fn<()> for my_func where T: Debug { extern "rust-call" fn call(&self, (): ()) -> () { {} } } //The rest of the `Fn*` family.
Note that you cannot have functions with unused generic parameters due to the trait-implementing nature of this method.
Macros
overloadable | Overloadable function macro. Please read the top level documentation for this crate for more information on this. |
overloadable_member | Overloadable function macro for members. This allows you to have overloadable methods and associated functions. |