def_mod!
provides a familiar syntax to the standard module declarations, but with the added benefit of being able
to easily define implementation routes and to statically verify module exports.
extern crate def_mod;
use def_mod;
def_mod!
NOTE: that def_mod
uses syntax tricks to assert for types.
So that means when you use the path shorthand, it will still only check the module that is loaded, not all potential modules.
Eg, if I've got a module that has two possible impls, one for windows and one for unix.
If I compile on windows, def_mod
can't check if the unix module has the correct symbols declared, because it's not the module that's compiled.
You would need to explicitly enable compilation of the modules you'd want to check, because you can declare
arbitrary #[cfg] attributes, there's no way in def_mod
to do this.
It's entirely up to you.
In case you're curious as to what the macro generates:
A method assertion is transformed to something like:
const _VALUE: fn = method;
A type assertion is transformed into a use decl, inside their own scope:
All of those are shoved into a function generated by the macro.
For example, given something like:
def_mod!
It'll turn it into something like this:
Disclaimer:
I'm still working on this, so it's possible not everything is implemented completely/correctly.
I know the method type signature conversion still needs some working on.
I want to add support for self, Self, and generics (Both lifetime and type).
If you've got an idea or two, feel free to give me a poke.