extfn - Extension Functions in Rust
extfn is a Rust library that implements extension functions, allowing any* freestanding function to
be called as a.foo(b) instead of foo(a, b) just by adding #[extfn] and renaming the first parameter to self.
use extfn;
use Ordering;
use Display;
use extfn;
use Ordering;
use Display;
Supported Function Signatures
A list of all supported function signatures can be found in tests/signatures.rs. Nearly everything I could think of is supported, with a few exceptions (see Fine Print).
Please report any edge cases where the "extfn transform" (add #[extfn] and rename the first parameter to self)
doesn't work.
Implementation Details
The #[extfn] macro essentially just converts a function into an extension trait with a single method.
This trait shares it's name with the extension function, allowing us to mark extension functions as pub and to import
them just like regular functions using use example::add1;, maintaining the illusion:
use add1;
Prior Art
Extension functions are already implemented in other programming languages:
As a Rust feature, extension functions have been proposed here, here, here, here.
Fine Print
- Const functions are unsupported because of E0379
self: T::Associs unsupported