MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / get_or_create

Method get_or_create

src/renderer.rs:333–343  ·  view source on GitHub ↗

Get the cached texture by its key, or create it using the provided function and cache it.

(&mut self, key: String, create_fn: F)

Source from the content-addressed store, hash-verified

331
332 /// Get the cached texture by its key, or create it using the provided function and cache it.
333 pub fn get_or_create<F>(&mut self, key: String, create_fn: F) -> &Texture2D
334 where F: FnOnce() -> Texture2D
335 {
336 if !self.textures.contains_key(&key) {
337 let texture = create_fn();
338 self.textures.insert(key.clone(), CacheEntry { frames_not_used: 0, owner: texture.into() });
339 }
340 let entry = self.textures.get_mut(&key).unwrap();
341 entry.frames_not_used = 0;
342 entry.owner.texture()
343 }
344
345 pub async fn get_or_create_async<F, Fut>(&mut self, key: String, create_fn: F) -> &Texture2D
346 where F: FnOnce() -> Fut,

Callers 1

renderFunction · 0.80

Calls 2

cloneMethod · 0.80
textureMethod · 0.80

Tested by

no test coverage detected