fn post_event<T: Event + ?Sized, static STUFF: AtomicUsize = ATOMIC_USIZE_INIT, static STUFF_INIT: Once = ONCE_INIT>(bus: &EventBus, event: &mut T) -> bool {
STUFF_INIT.call_once(|| initialization routine that uses STUFF);
let id = STUFF.load(Relaxed);
let downcasted_any = EVERYTHING[id].downcast_ref::<Handlers<T>>().expect("something");
// skipped
}
If the caller doesn’t specify where the statics are stored, and the default values are consts, they will be created at the call site with the specified const initializers. This allows a little code generation that’s not as powerful as macros and as such doesn’t need the ! at the end and can actually interact with the type system for once.
This allows high-performance code without adding “macro fns” like I suggested elsewhere.
" Rust is a systems programming language that runs blazingly fast, […] " - rust-lang.org
(* unless you’re trying to write high-performance code in 100% safe rust.)
This syntax does not look like it creates statics at the calls site,maybe you could change the syntax to be more evocative of what it’s doing.
I think it would be more obvious if the syntax was out static STUFF: AtomicUsize = ATOMIC_USIZE_INIT,and the syntax you have now was reserved for passing pre-existing statics.