fn main() {
let some = shader{};
fn init(){
println!("{}", "initialized.");
}
fn create(){
println!("{}", "created.");
some.compile(); // --------------> i want this to be accessible
}
fn update(){
println!("{}", "looping");
some.useHere(); // ----------------> and here
}
let mut x = app{
init: init,
create: create,
update: update
};
x.run();
}
Instead of storing closures, you can also use a trait:
pub trait App {
fn init(&mut self);
fn create(&mut self);
fn update(&mut self);
// I've made `run` a default method of App,
// You can also make it a freestanding function
// that takes any A: App
fn run(&mut self) {
self.init();
self.create();
for _ in 0..10 {
self.update();
}
}
}