Same concept, “functions” that are types and take types as arguments and put out types as outputs.
you may have noticed I talked about CTR and TypeFn separately? it’s because CTR is based on TypeFns - some TypeFns take a type and return supertraits, etc.
Currently, statics leak out of macros and it’s possible for two macro invokations to conflict.
I want them to not conflict, unless you explicitly tell them to.
I want hygienic macros.
Think of a sealed box. Macro inputs are pipes into that box. But when you use static/etc, it’s like throwing a hammer at the box. There’s a good chance it’ll cause a leak. I want this to be fixed.
Symbols don’t appear out past the module boundary unless you given them the blessing to do so, and even then, they must be explicitly imported to be used outside. And it should be easy enough for anyone to create their own fresh non-conflicting identifiers and pass them into the macro to be used for only the static. Don’t see what’s so hard about asking for a unique symbol from the user for the macro.
If you need even more wrapping from the outside, you can declare inner modules, macro-generated or otherwise.
Returning a list of traits would look like this then?:
types![ dyn Debug,dyn Display ]
Then,assuming we get reflection for getting supertraits, you could ask if the supertraits are exactly Display and Debug by doing this:
Self:SuperTraits<Output=types![ dyn Debug,dyn Display ]>
types being a macro for producing a list of types.
but, in my code, I want to inspect and use supertraits at compile-time.
compare eventbus (my crate) semantics, with minecraftforge event bus (inspiration) semantics. they’re currently very different and I’d like to bring them closer.
I can’t help you with the type tricks you want to pull off, but as for some way of getting even more collision resistance of identifiers here’s a demonstration of creation of modules in macros, which allows for most of the heightened privacy you want in your macros:
I am looking at this page and I can’t see anything that would require listing traits instead of listing types/trait impls when translated to Rust.
I would be in favor of adding reflection to Rust such that one can list the types that satisfy a particular constraint,using either a hlist encoding (List<value0,List<value2,Nil>>) or with variadics.
let myevent = MyEvent(0);
post!(bus, dyn Event, dyn MyEventsPurpose, MyEvent, &mut myevent); // too error-prone, you could forget a supertrait or another.
I don’t believe your solution works anything like this but allows omitting the types?
You should try actually using the Forge bus, and then actually using my eventbus, rather than working based on assumptions.
And maybe you could explain what your constraints are and what you’re trying to achieve rather than expecting others to figure it out.
You know better than anyone else what you want. If you don’t explain it, there’s always going to be a difference between your view of the problem and others’ understanding.
Also, trying to translate Java patterns straight into Rust is a recipe for making your API look foreign to Rust users, and feel subtly off for Java users, if not worse.
From what I can read of the Forge docs, you might have better success creating an idiomatic Rust API with Futures, handles to these futures, and a dispatcher that will poll the ones registered for a particular event when it happens. Rust Futures don’t make progress unless polled, which may seem like a burden, but allow for a future to be abruptly cancelled if desired simply by dropping it from the futures to be polled the next time around.