Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/optimisticpeach/overloadable
Overloadable functions in rust.
https://github.com/optimisticpeach/overloadable
Last synced: 2 months ago
JSON representation
Overloadable functions in rust.
- Host: GitHub
- URL: https://github.com/optimisticpeach/overloadable
- Owner: OptimisticPeach
- License: mit
- Created: 2019-07-13T22:46:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-08T21:13:59.000Z (over 5 years ago)
- Last Synced: 2024-10-13T08:45:06.446Z (3 months ago)
- Language: Rust
- Size: 22.5 KB
- Stars: 41
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
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:
```rust
#![feature(unboxed_closures, fn_traits)]
```## Example:
```rust
#![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);
}
```