Comment

Comment by coolreader18

Drawable is just a trait, a definition of methods that can be abstracted over. If you wanted to store data, you'd do it in the type that Drawable is actually being implemented for, i.e. MyEntity.

    struct MyEntity {
        cache: RenderingCache,
    }
    impl Drawable for MyEntity {
        fn draw(&self, canvas: &mut Canvas) {
            self.cache.draw_cached(canvas, |cache_canvas| {
                cache_canvas.render(ASSET);
            });
        }
    }
    const ASSET: Asset = load_asset("foo.png");

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton