Re: Audio Games with Rust?
Update: So looking at Bevy, or the rustdocs at least, it looks like a lot of magic and very little explanation. For example, the example has this line:
App::build()
.add_system(hello_world_system.system())
.run();
That hello_world_system thing is defined as:
fn hello_world_system() {
println!("hello world");
}
Yet the .add_system() function looks like:
pub fn add_system(&mut self, system: Box<dyn System>) -> &mut Self
This makes no sense to me. The hello_world_system() function returns unit. Therefore, what magic is exactly going on? Because according to the example, the function has no annotations, proc-macros, derivations... nothing. Its just an ordinary rust function, indistinguishable from main(). To add to that, the .system() function is called on the function as though it were an initialized structure. And rust syntax does not allow you to do calls like that on functions -- you have to do that on their return values (I don't know a language that treats functions as objects like this seems to do). So, I'm utterly baffled.... what exactly is going on?
Edit: OK, so the book explains it... sort of. Its apparently a trait extension type, which I've never seen until now (I don't think). Interesting paradigm, if I might say so myself, and an interesting use of the type system.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector