Re: Audio Games with Rust?

@12
Should have held off on posting and I could have gotten all the answers in both, but I'm 99.99% sure that all that is is they implemented their traits in terms of Fn, FnMut, and FnOnce from the ops module. You can do:

impl<T: YourTrait> MyTrait for T {
}

And then MyTrait is on everything that impls YourTrait.  You can't impl the Fn traits yourself without being on nightly but as far as I know absolutely nothing stops you implementing other traits in terms of them.

Dyn is just Rust 2018 syntax for trait objects.  I'm pretty sure that those two features get you as far as bevy, I don't think it needs anything more than that.

The last trick, though, is that with some macro magic you can define macros that call macros, and one of those macros can call another macro like M!(a) m!(a, b) m!(a, b, c), etc. up to a specified number of parameters.  This lets you then get around Rust's lack of variadic generics to impl your traits that want to use tuples and/or callables and/or whatever for up to however many arguments.  Most libraries that do this stop at 32.  You can then go one step further and make the trait your implementing for the tuple know how to return a runtime description of it using std::TypeId, which with not that much more cleverness lets you build HashMap<TypeId, Any> and do type-safe runtime dynamic access to it, and if your original trait that let you bridge this far contains the logic for manipulating the Any it can just be asked nicely to unpack the Any and do whatever, without the piece driving all of this ever even knowing what the types were, and you've just safely abstracted this out to an interface that is basically "please hold these two opaque values for me and give them back when I ask" as your driver.  it's even sufficient to do scheduling based off dependencies: TypeId is Eq, Ord, etc., so you can compare them and sort them and such.

Obviously in practice it's like HashMap<Vec<TypeId>, Any> or whatever, and there's libraries to make it much easier, but this is the idea.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nolan via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nolan via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nolan via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Gaki_shonen via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nolan via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nolan via Audiogames-reflector

Reply via email to